{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# CA 函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "# 耦合角的计算方式,输入值为角度,最好是已经插完值的，一般插值为101个样本量，模式2必须插值。\n",
    "def CA(A1, A2, mode):\n",
    "    y1 = np.zeros((min(A1.shape[0], A2.shape[0])-1, 1))\n",
    "    # 协调性比例\n",
    "    for i in range(y1.shape[0]):\n",
    "        if A2[i+1]-A2[i] == 0:\n",
    "            if A1[i+1]-A1[i] > 0:\n",
    "                y1[i, 0] = 90\n",
    "            elif A1[i+1]-A1[i] > 0:\n",
    "                y1[i, 0] = 270\n",
    "            else:\n",
    "                y1[i, 0] = None\n",
    "        elif A2[i+1]-A2[i]>0:\n",
    "            y1[i, 0] = np.arctan((A1[i+1]-A1[i])/(A2[i+1]-A2[i]))*180/np.pi\n",
    "        else:\n",
    "            if A1[i] == A1[i+1]:\n",
    "                y1[i, 0] = 180\n",
    "            else:\n",
    "                y1[i, 0] = np.arctan((A1[i+1]-A1[i])/(A2[i+1]-A2[i]))*180/np.pi + 180\n",
    "        if y1[i, 0] < 0:\n",
    "            y1[i, 0] = y1[i, 0] + 360\n",
    "        else:\n",
    "            y1[i, 0] = y1[i, 0]\n",
    "\n",
    "    if mode == 1:\n",
    "        y = y1\n",
    "    elif mode ==2:\n",
    "        y2 = np.zeros((y1.shape[0], 1))\n",
    "        for mm in range(y1.shape[0]):\n",
    "            # 1表示in-phase；2表示anti-phase；3表示D远端环节主导，即A1；4表示近端环节主导即A2\n",
    "            if 22.5<=y1[mm, 0] and y1[mm, 0]<67.5:\n",
    "                y2[mm, 0] = 1\n",
    "            elif 67.5<=y1[mm, 0] and y1[mm, 0]<112.5:\n",
    "                y2[mm, 0] = 3\n",
    "            elif 112.5<=y1[mm, 0] and y1[mm, 0]<157.5:\n",
    "                y2[mm, 0] = 2\n",
    "            elif 157.5<=y1[mm, 0] and y1[mm, 0]<202.5:\n",
    "                y2[mm, 0] = 4\n",
    "            elif 202.5<=y1[mm, 0] and y1[mm, 0]<247.5:\n",
    "                y2[mm, 0] = 1\n",
    "            elif 247.5<=y1[mm, 0] and y1[mm, 0]<292.5:\n",
    "                y2[mm, 0] = 3\n",
    "            elif 292.5<=y1[mm, 0] and y1[mm, 0]<337.5:\n",
    "                y2[mm, 0] = 2\n",
    "            elif 337.5<=y1[mm, 0] and y1[mm, 0]<360:\n",
    "                y2[mm, 0] = 4\n",
    "            elif 0<=y1[mm, 0] and y1[mm, 0]<22.5:\n",
    "                y2[mm, 0] = 4\n",
    "            else:\n",
    "                y2[mm, 0] = None\n",
    "        y3 = np.zeros((y1.shape[0], 1))\n",
    "        y3[0, 0] = np.sum(y2 == 1)\n",
    "        y3[1, 0] = np.sum(y2 == 2)\n",
    "        y3[2, 0] = np.sum(y2 == 3)\n",
    "        y3[3, 0] = np.sum(y2 == 4)\n",
    "        y3[4:, 0] = None\n",
    "\n",
    "        y=np.c_[y1,y3]\n",
    "    else:\n",
    "        y=y1\n",
    "\n",
    "#     print(y)\n",
    "    return y"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 一级运动员途中，加速，冲刺对比"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "from openpyxl import load_workbook\n",
    "import  pandas  as pd\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "def removeNan(data1):\n",
    "    try:\n",
    "        x = np.where(np.isnan(data1)==True)[0]\n",
    "        data1 = data1.tolist()\n",
    "        for i in range(len(x)-1,-1,-1):\n",
    "            data1.remove(data1[x[i]])\n",
    "    except:\n",
    "        data1 = data1.tolist()\n",
    "    return data1\n",
    "\n",
    "def getData(data, xindex=None, yindex=None):\n",
    "    # 获取数据\n",
    "    index1 = data[data.iloc[:,xindex]=='后摆阶段'].index.tolist()[0]\n",
    "    index2 = data[data.iloc[:,xindex]=='前摆阶段'].index.tolist()[0]\n",
    "    index3 = data[data.iloc[:,xindex]=='支撑阶段'].index.tolist()[0]\n",
    "    data1 = np.array(data.iloc[index1:index2, [yindex]]).T[0]\n",
    "    data1 = removeNan(data1)\n",
    "    data2 = np.array(data.iloc[index2:index3, [yindex]]).T[0]\n",
    "    data2 = removeNan(data2)\n",
    "    data3 = np.array(data.iloc[index3:, [yindex]]).T[0]\n",
    "    data3= removeNan(data3)\n",
    "    return lineInsert(data1), lineInsert(data2), lineInsert(data3)\n",
    "\n",
    "def getDataFull(data, xindex=None, yindex=None):\n",
    "    # 获取数据\n",
    "    index1 = data[data.iloc[:,xindex]=='后摆阶段'].index.tolist()[0]\n",
    "    index2 = data[data.iloc[:,xindex]=='前摆阶段'].index.tolist()[0]\n",
    "    index3 = data[data.iloc[:,xindex]=='支撑阶段'].index.tolist()[0]\n",
    "    data1 = np.array(data.iloc[index1:index2, [yindex]]).T[0]\n",
    "    data1 = removeNan(data1)\n",
    "    data2 = np.array(data.iloc[index2:index3, [yindex]]).T[0]\n",
    "    data2 = removeNan(data2)\n",
    "    data3 = np.array(data.iloc[index3:, [yindex]]).T[0]\n",
    "    data3= removeNan(data3)\n",
    "    data = data1+data2[1:]+data3[1:]\n",
    "    return lineInsert(data)\n",
    "\n",
    "def lineInsert(data1):\n",
    "    data1_ = np.zeros((101,1))\n",
    "    interval = int((data1_.shape[0]+(len(data1)-1)-2)/(len(data1)-1))\n",
    "    data1_[0:interval, 0] = np.linspace(data1[0], data1[1], interval)\n",
    "    for i in range(0, len(data1)-3):\n",
    "        data1_[interval+i*(interval-1):interval+i*(interval-1)+(interval-1), 0] = np.linspace(data1[i+1], data1[i+2], interval)[1: ]\n",
    "    surplus_number = data1_.shape[0]-interval-(interval - 1)*(len(data1)-3)\n",
    "    data1_[-surplus_number-1: , 0] = np.linspace(data1[-2], data1[-1], surplus_number+1)\n",
    "    return data1_\n",
    "\n",
    "dict_ = {}\n",
    "for k in ['途中','加速','冲刺']:\n",
    "    root = 'C:/code/北体数据处理/肢体角度数据/一级运动员数据/一级运动员{}跑数据.xlsx'.format(k)\n",
    "    wb = load_workbook(root)\n",
    "    sheets = wb.worksheets   # 获取当前所有的sheet\n",
    "    for ss in range(len(sheets)):\n",
    "        sheet1 = sheets[ss]\n",
    "        df=pd.read_excel(root,sheet_name=sheet1.title)\n",
    "        data=df.head(n=sheet1.max_row)\n",
    "        data1 = getDataFull(data, xindex=0, yindex=1)\n",
    "        data2 = getDataFull(data, xindex=0, yindex=2)\n",
    "        data3 = getDataFull(data, xindex=0, yindex=3)\n",
    "        data4 = getDataFull(data, xindex=5, yindex=6)\n",
    "        data5 = getDataFull(data, xindex=5, yindex=7)\n",
    "        data6 = getDataFull(data, xindex=5, yindex=8)\n",
    "        pair = [[1,2],[2,3],[4,5],[5,6]]\n",
    "        for i in pair:\n",
    "            str_ = ''\n",
    "            str_+=k+'_'\n",
    "            if i == [1,2]:str_+='The left hip with The left knee'\n",
    "            if i == [2,3]:str_+='The left knee with The left ankle'\n",
    "            if i == [4,5]:str_+='The right hip with The right knee'\n",
    "            if i == [5,6]:str_+='The right knee with The right ankle'\n",
    "            num_ = CA(eval('data{}'.format(i[0])), eval('data{}'.format(i[1])), 2)[:4,1]\n",
    "            if str_ not in dict_.keys():\n",
    "                dict_[str_] = []\n",
    "                dict_[str_].append(num_.tolist())\n",
    "            else:\n",
    "                dict_[str_].append(num_.tolist())\n",
    "print(len(dict_.keys()))\n",
    "\n",
    "def plot(title):\n",
    "    for i in range(len(list(dict_.keys()))):\n",
    "        value = dict_[list(dict_.keys())[i]]\n",
    "        dict_[list(dict_.keys())[i]] = np.array(value)\n",
    "        value = dict_[list(dict_.keys())[i]]\n",
    "        mean_ = value.mean(0) \n",
    "        std_ = value.std(0)\n",
    "        error_params=dict(elinewidth=1,ecolor='k',capsize=6)\n",
    "        width = 0.25\n",
    "        if title in list(dict_.keys())[i]: \n",
    "            if '途中' in list(dict_.keys())[i]:\n",
    "                plt.bar(x=[1-width, 2-width, 3-width, 4-width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C0',\n",
    "                       label='Midway')\n",
    "            if '加速' in list(dict_.keys())[i]:\n",
    "                plt.bar(x=[1, 2, 3, 4], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C2',\n",
    "                       label='Boost')\n",
    "            if '冲刺' in list(dict_.keys())[i]:\n",
    "                plt.bar(x=[1+width, 2+width, 3+width, 4+width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C1',\n",
    "                       label='Sprint')\n",
    "    plt.xticks([1,2,3,4],['In\\n-phase','Anti\\n-phase','A1','A2'],fontsize=16)\n",
    "    plt.yticks(fontsize=16)\n",
    "    plt.legend(fontsize=12,loc='upper right')\n",
    "    plt.ylabel('Number',fontsize=18)\n",
    "    plt.title(title, fontsize=20)\n",
    "\n",
    "plot('The left hip with The left knee')\n",
    "plt.savefig('Figure/一级运动员对比（左髋关节&左膝关节）.jpg',dpi=300,bbox_inches = 'tight')\n",
    "plt.show()\n",
    "abc\n",
    "plot('The left knee with The left ankle')\n",
    "plt.savefig('Figure/一级运动员对比（左膝关节&左踝关节）.jpg',dpi=300,bbox_inches = 'tight')\n",
    "plt.show()\n",
    "plot('The right hip with The right knee')\n",
    "plt.savefig('Figure/一级运动员对比（右髋关节&右膝关节）.jpg',dpi=300,bbox_inches = 'tight')\n",
    "plt.show()\n",
    "plot('The right knee with The right ankle')\n",
    "plt.savefig('Figure/一级运动员对比（右膝关节&右踝关节）.jpg',dpi=300,bbox_inches = 'tight')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 三个阶段分开（比较途中，加速，冲刺）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from openpyxl import load_workbook\n",
    "import  pandas  as pd\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "def removeNan(data1):\n",
    "    try:\n",
    "        x = np.where(np.isnan(data1)==True)[0]\n",
    "        data1 = data1.tolist()\n",
    "        for i in range(len(x)-1,-1,-1):\n",
    "            data1.remove(data1[x[i]])\n",
    "    except:\n",
    "        data1 = data1.tolist()\n",
    "    return data1\n",
    "\n",
    "def getData(data, xindex=None, yindex=None):\n",
    "    # 获取数据\n",
    "    index1 = data[data.iloc[:,xindex]=='后摆阶段'].index.tolist()[0]\n",
    "    index2 = data[data.iloc[:,xindex]=='前摆阶段'].index.tolist()[0]\n",
    "    index3 = data[data.iloc[:,xindex]=='支撑阶段'].index.tolist()[0]\n",
    "    data1 = np.array(data.iloc[index1:index2, [yindex]]).T[0]\n",
    "    data1 = removeNan(data1)\n",
    "    data2 = np.array(data.iloc[index2:index3, [yindex]]).T[0]\n",
    "    data2 = removeNan(data2)\n",
    "    data3 = np.array(data.iloc[index3:, [yindex]]).T[0]\n",
    "    data3= removeNan(data3)\n",
    "    return lineInsert(data1), lineInsert(data2), lineInsert(data3)\n",
    "\n",
    "def getDataFull(data, xindex=None, yindex=None):\n",
    "    # 获取数据\n",
    "    index1 = data[data.iloc[:,xindex]=='后摆阶段'].index.tolist()[0]\n",
    "    index2 = data[data.iloc[:,xindex]=='前摆阶段'].index.tolist()[0]\n",
    "    index3 = data[data.iloc[:,xindex]=='支撑阶段'].index.tolist()[0]\n",
    "    data1 = np.array(data.iloc[index1:index2, [yindex]]).T[0]\n",
    "    data1 = removeNan(data1)\n",
    "    data2 = np.array(data.iloc[index2:index3, [yindex]]).T[0]\n",
    "    data2 = removeNan(data2)\n",
    "    data3 = np.array(data.iloc[index3:, [yindex]]).T[0]\n",
    "    data3= removeNan(data3)\n",
    "    data = data1+data2[1:]+data3[1:]\n",
    "    return lineInsert(data)\n",
    "\n",
    "def lineInsert(data1):\n",
    "    data1_ = np.zeros((101,1))\n",
    "    interval = int((data1_.shape[0]+(len(data1)-1)-2)/(len(data1)-1))\n",
    "    data1_[0:interval, 0] = np.linspace(data1[0], data1[1], interval)\n",
    "    for i in range(0, len(data1)-3):\n",
    "        data1_[interval+i*(interval-1):interval+i*(interval-1)+(interval-1), 0] = np.linspace(data1[i+1], data1[i+2], interval)[1: ]\n",
    "    surplus_number = data1_.shape[0]-interval-(interval - 1)*(len(data1)-3)\n",
    "    data1_[-surplus_number-1: , 0] = np.linspace(data1[-2], data1[-1], surplus_number+1)\n",
    "    return data1_\n",
    "\n",
    "dict_ = {}\n",
    "dict_all = {}\n",
    "for k in ['途中','加速','冲刺']:\n",
    "    root = 'C:/code/北体数据处理/肢体角度数据/一级运动员数据/一级运动员{}跑数据.xlsx'.format(k)\n",
    "    wb = load_workbook(root)\n",
    "    sheets = wb.worksheets   # 获取当前所有的sheet\n",
    "    for ss in range(len(sheets)):\n",
    "        sheet1 = sheets[ss]\n",
    "        df=pd.read_excel(root,sheet_name=sheet1.title)\n",
    "        data=df.head(n=sheet1.max_row)\n",
    "        data1_1, data1_2, data1_3 = getData(data, xindex=0, yindex=1) # 读取所有数据\n",
    "        data2_1, data2_2, data2_3 = getData(data, xindex=0, yindex=2)\n",
    "        data3_1, data3_2, data3_3 = getData(data, xindex=0, yindex=3)\n",
    "        data4_1, data4_2, data4_3 = getData(data, xindex=5, yindex=6)\n",
    "        data5_1, data5_2, data5_3 = getData(data, xindex=5, yindex=7)\n",
    "        data6_1, data6_2, data6_3 = getData(data, xindex=5, yindex=8)\n",
    "        pair = [[1,2],[2,3],[4,5],[5,6]]\n",
    "        for i in pair:\n",
    "            for j in range(1,4):\n",
    "                str_ = ''\n",
    "                str_+=k+'_'\n",
    "                if i == [1,2]:str_+='The left hip with The left knee'\n",
    "                if i == [2,3]:str_+='The left knee with The left ankle'\n",
    "                if i == [4,5]:str_+='The right hip with The right knee'\n",
    "                if i == [5,6]:str_+='The right knee with The right ankle'\n",
    "                if j == 1: str_+=' in\\n The phase of swinging back_1'\n",
    "                if j == 2: str_+=' in\\n The phase of swinging forward_2'\n",
    "                if j == 3: str_+=' in\\n The phase of support_3'\n",
    "                num_ = CA(eval('data{}_{}'.format(i[0], j)), eval('data{}_{}'.format(i[1], j)), 2)[:4,1]\n",
    "                num_all = CA(eval('data{}_{}'.format(i[0], j)), eval('data{}_{}'.format(i[1], j)), 2)\n",
    "                if str_ not in dict_.keys():\n",
    "                    dict_[str_] = []\n",
    "                    dict_[str_].append(num_.tolist())\n",
    "                    dict_all[str_] = []\n",
    "                    dict_all[str_].append(num_all.tolist())\n",
    "                else:\n",
    "                    dict_[str_].append(num_.tolist())\n",
    "                    dict_all[str_].append(num_all.tolist())\n",
    "# print(dict_.keys())\n",
    "\n",
    "def plot(title,phase):\n",
    "    for i in range(len(list(dict_.keys()))):\n",
    "        value = dict_[list(dict_.keys())[i]]\n",
    "        ouhejiao = dict_all[list(dict_.keys())[i]]\n",
    "        dict_[list(dict_.keys())[i]] = np.array(value)\n",
    "        value = dict_[list(dict_.keys())[i]]\n",
    "        mean_ = value.mean(0) \n",
    "        std_ = value.std(0)\n",
    "        error_params=dict(elinewidth=1,ecolor='k',capsize=6)\n",
    "        width = 0.25\n",
    "        if title in list(dict_.keys())[i]: \n",
    "            if phase in list(dict_.keys())[i]:\n",
    "#                 print(list(dict_.keys())[i])\n",
    "                if '途中' in list(dict_.keys())[i]:\n",
    "                    plt.bar(x=[1-width, 2-width, 3-width, 4-width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C0',\n",
    "                           label='Midway')\n",
    "                if '加速' in list(dict_.keys())[i]:\n",
    "                    plt.bar(x=[1, 2, 3, 4], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C2',\n",
    "                           label='Boost')\n",
    "                if '冲刺' in list(dict_.keys())[i]:\n",
    "                    plt.bar(x=[1+width, 2+width, 3+width, 4+width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C1',\n",
    "                           label='Sprint')\n",
    "    plt.xticks([1,2,3,4],['In\\n-phase','Anti\\n-phase','A1','A2'],fontsize=16)\n",
    "    plt.yticks(fontsize=16)\n",
    "    plt.legend(fontsize=12,loc='upper right')\n",
    "    plt.ylabel('Number',fontsize=18)\n",
    "    if phase == '1': title+=' in\\n The phase of swinging back'\n",
    "    if phase == '2': title+=' in\\n The phase of swinging forward'\n",
    "    if phase == '3': title+=' in\\n The phase of support'\n",
    "    print(title, mean_, std_) # 标题，绘图的均值，方差，每个都保存到一个文件中，文件名可以用保存的图的文件名\n",
    "    print(title)\n",
    "    for i in range(len(ouhejiao)): # 每张图的每个柱子是不同不同耦合角计算的统计数据，包括均值和方差。这里输出的是原始的耦合角的数据，也要保存下来，可以另一个文件，区分好就可以\n",
    "        print(ouhejiao[i])\n",
    "    plt.title(title, fontsize=20)\n",
    "\n",
    "for i in range(1,4):\n",
    "    plot('The left hip with The left knee', '{}'.format(i))\n",
    "    plt.savefig('Figure/一级运动员对比（左髋关节&左膝关节）_{}.jpg'.format(i),dpi=300,bbox_inches = 'tight')\n",
    "    plt.show()\n",
    "    plot('The left knee with The left ankle', '{}'.format(i))\n",
    "    plt.savefig('Figure/一级运动员对比（左膝关节&左踝关节）_{}.jpg'.format(i),dpi=300,bbox_inches = 'tight')\n",
    "    plt.show()\n",
    "    plot('The right hip with The right knee', '{}'.format(i))\n",
    "    plt.savefig('Figure/一级运动员对比（右髋关节&右膝关节）_{}.jpg'.format(i),dpi=300,bbox_inches = 'tight')\n",
    "    plt.show()\n",
    "    plot('The right knee with The right ankle', '{}'.format(i))\n",
    "    plt.savefig('Figure/一级运动员对比（右膝关节&右踝关节）_{}.jpg'.format(i),dpi=300,bbox_inches = 'tight')\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 三个阶段分开（比较前摆，后摆，支撑）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from openpyxl import load_workbook\n",
    "import  pandas  as pd\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "def removeNan(data1):\n",
    "    try:\n",
    "        x = np.where(np.isnan(data1)==True)[0]\n",
    "        data1 = data1.tolist()\n",
    "        for i in range(len(x)-1,-1,-1):\n",
    "            data1.remove(data1[x[i]])\n",
    "    except:\n",
    "        data1 = data1.tolist()\n",
    "    return data1\n",
    "\n",
    "def getData(data, xindex=None, yindex=None):\n",
    "    # 获取数据\n",
    "    index1 = data[data.iloc[:,xindex]=='后摆阶段'].index.tolist()[0]\n",
    "    index2 = data[data.iloc[:,xindex]=='前摆阶段'].index.tolist()[0]\n",
    "    index3 = data[data.iloc[:,xindex]=='支撑阶段'].index.tolist()[0]\n",
    "    data1 = np.array(data.iloc[index1:index2, [yindex]]).T[0]\n",
    "    data1 = removeNan(data1)\n",
    "    data2 = np.array(data.iloc[index2:index3, [yindex]]).T[0]\n",
    "    data2 = removeNan(data2)\n",
    "    data3 = np.array(data.iloc[index3:, [yindex]]).T[0]\n",
    "    data3= removeNan(data3)\n",
    "    return lineInsert(data1), lineInsert(data2), lineInsert(data3)\n",
    "\n",
    "def getDataFull(data, xindex=None, yindex=None):\n",
    "    # 获取数据\n",
    "    index1 = data[data.iloc[:,xindex]=='后摆阶段'].index.tolist()[0]\n",
    "    index2 = data[data.iloc[:,xindex]=='前摆阶段'].index.tolist()[0]\n",
    "    index3 = data[data.iloc[:,xindex]=='支撑阶段'].index.tolist()[0]\n",
    "    data1 = np.array(data.iloc[index1:index2, [yindex]]).T[0]\n",
    "    data1 = removeNan(data1)\n",
    "    data2 = np.array(data.iloc[index2:index3, [yindex]]).T[0]\n",
    "    data2 = removeNan(data2)\n",
    "    data3 = np.array(data.iloc[index3:, [yindex]]).T[0]\n",
    "    data3= removeNan(data3)\n",
    "    data = data1+data2[1:]+data3[1:]\n",
    "    return lineInsert(data)\n",
    "\n",
    "def lineInsert(data1):\n",
    "    data1_ = np.zeros((101,1))\n",
    "    interval = int((data1_.shape[0]+(len(data1)-1)-2)/(len(data1)-1))\n",
    "    data1_[0:interval, 0] = np.linspace(data1[0], data1[1], interval)\n",
    "    for i in range(0, len(data1)-3):\n",
    "        data1_[interval+i*(interval-1):interval+i*(interval-1)+(interval-1), 0] = np.linspace(data1[i+1], data1[i+2], interval)[1: ]\n",
    "    surplus_number = data1_.shape[0]-interval-(interval - 1)*(len(data1)-3)\n",
    "    data1_[-surplus_number-1: , 0] = np.linspace(data1[-2], data1[-1], surplus_number+1)\n",
    "    return data1_\n",
    "\n",
    "dict_ = {}\n",
    "for k in ['途中','加速','冲刺']:\n",
    "    root = 'C:/code/北体数据处理/肢体角度数据/一级运动员数据/一级运动员{}跑数据.xlsx'.format(k)\n",
    "    wb = load_workbook(root)\n",
    "    sheets = wb.worksheets   # 获取当前所有的sheet\n",
    "    for ss in range(len(sheets)):\n",
    "        sheet1 = sheets[ss]\n",
    "        df=pd.read_excel(root,sheet_name=sheet1.title)\n",
    "        data=df.head(n=sheet1.max_row)\n",
    "        data1_1, data1_2, data1_3 = getData(data, xindex=0, yindex=1) # 读取所有数据\n",
    "        data2_1, data2_2, data2_3 = getData(data, xindex=0, yindex=2)\n",
    "        data3_1, data3_2, data3_3 = getData(data, xindex=0, yindex=3)\n",
    "        data4_1, data4_2, data4_3 = getData(data, xindex=5, yindex=6)\n",
    "        data5_1, data5_2, data5_3 = getData(data, xindex=5, yindex=7)\n",
    "        data6_1, data6_2, data6_3 = getData(data, xindex=5, yindex=8)\n",
    "        pair = [[1,2],[2,3],[4,5],[5,6]]\n",
    "        for i in pair:\n",
    "            for j in range(1,4):\n",
    "                str_ = ''\n",
    "                str_+=k+'_'\n",
    "                if i == [1,2]:str_+='The left hip with The left knee'\n",
    "                if i == [2,3]:str_+='The left knee with The left ankle'\n",
    "                if i == [4,5]:str_+='The right hip with The right knee'\n",
    "                if i == [5,6]:str_+='The right knee with The right ankle'\n",
    "                if j == 1: str_+=' in\\n The phase of swinging back_1'\n",
    "                if j == 2: str_+=' in\\n The phase of swinging forward_2'\n",
    "                if j == 3: str_+=' in\\n The phase of support_3'\n",
    "                num_ = CA(eval('data{}_{}'.format(i[0], j)), eval('data{}_{}'.format(i[1], j)), 2)[:4,1]\n",
    "                if str_ not in dict_.keys():\n",
    "                    dict_[str_] = []\n",
    "                    dict_[str_].append(num_.tolist())\n",
    "                else:\n",
    "                    dict_[str_].append(num_.tolist())\n",
    "print(dict_.keys())\n",
    "\n",
    "def plot(title,phase):\n",
    "    for i in range(len(list(dict_.keys()))):\n",
    "        value = dict_[list(dict_.keys())[i]]\n",
    "        dict_[list(dict_.keys())[i]] = np.array(value)\n",
    "        value = dict_[list(dict_.keys())[i]]\n",
    "        mean_ = value.mean(0) \n",
    "        std_ = value.std(0)\n",
    "        error_params=dict(elinewidth=1,ecolor='k',capsize=6)\n",
    "        width = 0.25\n",
    "        if title in list(dict_.keys())[i]: \n",
    "            if '途中' in list(dict_.keys())[i] and phase=='1':\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '1':\n",
    "                    plt.bar(x=[1-width, 2-width, 3-width, 4-width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C0',\n",
    "                           label='Swinging back')\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '2':\n",
    "                    plt.bar(x=[1, 2, 3, 4], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C2',\n",
    "                           label='Swinging forward')\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '3':\n",
    "                    plt.bar(x=[1+width, 2+width, 3+width, 4+width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C1',\n",
    "                           label='Support')\n",
    "            if '加速' in list(dict_.keys())[i] and phase=='2':\n",
    "                print('ssss')\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '1':\n",
    "                    plt.bar(x=[1-width, 2-width, 3-width, 4-width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C0',\n",
    "                           label='Swinging back')\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '2':\n",
    "                    plt.bar(x=[1, 2, 3, 4], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C2',\n",
    "                           label='Swinging forward')\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '3':\n",
    "                    plt.bar(x=[1+width, 2+width, 3+width, 4+width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C1',\n",
    "                           label='Support')\n",
    "            if '冲刺' in list(dict_.keys())[i] and phase=='3':\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '1':\n",
    "                    plt.bar(x=[1-width, 2-width, 3-width, 4-width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C0',\n",
    "                           label='Swinging back')\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '2':\n",
    "                    plt.bar(x=[1, 2, 3, 4], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C2',\n",
    "                           label='Swinging forward')\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '3':\n",
    "                    plt.bar(x=[1+width, 2+width, 3+width, 4+width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C1',\n",
    "                           label='Support')\n",
    "    plt.xticks([1,2,3,4],['In\\n-phase','Anti\\n-phase','A1','A2'],fontsize=16)\n",
    "    plt.yticks(fontsize=16)\n",
    "    plt.legend(fontsize=12,loc='upper right')\n",
    "    plt.ylabel('Number',fontsize=18)\n",
    "    if phase == '1': title+=' \\nin Midway'\n",
    "    if phase == '2': title+=' \\nin Boost'\n",
    "    if phase == '3': title+=' \\nin Sprint'\n",
    "    plt.title(title, fontsize=20)\n",
    "\n",
    "for i in range(1,4):\n",
    "    plot('The left hip with The left knee', '{}'.format(i))\n",
    "    plt.savefig('Figure/一级运动员对比（左髋关节&左膝关节）_{}_s.jpg'.format(i),dpi=300,bbox_inches = 'tight')\n",
    "    plt.show()\n",
    "    plot('The left knee with The left ankle', '{}'.format(i))\n",
    "    plt.savefig('Figure/一级运动员对比（左膝关节&左踝关节）_{}_s.jpg'.format(i),dpi=300,bbox_inches = 'tight')\n",
    "    plt.show()\n",
    "    plot('The right hip with The right knee', '{}'.format(i))\n",
    "    plt.savefig('Figure/一级运动员对比（右髋关节&右膝关节）_{}_s.jpg'.format(i),dpi=300,bbox_inches = 'tight')\n",
    "    plt.show()\n",
    "    plot('The right knee with The right ankle', '{}'.format(i))\n",
    "    plt.savefig('Figure/一级运动员对比（右膝关节&右踝关节）_{}_s.jpg'.format(i),dpi=300,bbox_inches = 'tight')\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 二级运动员途中，加速，冲刺对比"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "from openpyxl import load_workbook\n",
    "import  pandas  as pd\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "def removeNan(data1):\n",
    "    try:\n",
    "        x = np.where(np.isnan(data1)==True)[0]\n",
    "        data1 = data1.tolist()\n",
    "        for i in range(len(x)-1,-1,-1):\n",
    "            data1.remove(data1[x[i]])\n",
    "    except:\n",
    "        data1 = data1.tolist()\n",
    "    return data1\n",
    "\n",
    "def getData(data, xindex=None, yindex=None):\n",
    "    # 获取数据\n",
    "    index1 = data[data.iloc[:,xindex]=='后摆阶段'].index.tolist()[0]\n",
    "    index2 = data[data.iloc[:,xindex]=='前摆阶段'].index.tolist()[0]\n",
    "    index3 = data[data.iloc[:,xindex]=='支撑阶段'].index.tolist()[0]\n",
    "    data1 = np.array(data.iloc[index1:index2, [yindex]]).T[0]\n",
    "    data1 = removeNan(data1)\n",
    "    data2 = np.array(data.iloc[index2:index3, [yindex]]).T[0]\n",
    "    data2 = removeNan(data2)\n",
    "    data3 = np.array(data.iloc[index3:, [yindex]]).T[0]\n",
    "    data3= removeNan(data3)\n",
    "    return lineInsert(data1), lineInsert(data2), lineInsert(data3)\n",
    "\n",
    "def getDataFull(data, xindex=None, yindex=None):\n",
    "    # 获取数据\n",
    "    index1 = data[data.iloc[:,xindex]=='后摆阶段'].index.tolist()[0]\n",
    "    index2 = data[data.iloc[:,xindex]=='前摆阶段'].index.tolist()[0]\n",
    "    index3 = data[data.iloc[:,xindex]=='支撑阶段'].index.tolist()[0]\n",
    "    data1 = np.array(data.iloc[index1:index2, [yindex]]).T[0]\n",
    "    data1 = removeNan(data1)\n",
    "    data2 = np.array(data.iloc[index2:index3, [yindex]]).T[0]\n",
    "    data2 = removeNan(data2)\n",
    "    data3 = np.array(data.iloc[index3:, [yindex]]).T[0]\n",
    "    data3= removeNan(data3)\n",
    "    data = data1+data2[1:]+data3[1:]\n",
    "    return lineInsert(data)\n",
    "\n",
    "def lineInsert(data1):\n",
    "    data1_ = np.zeros((101,1))\n",
    "    interval = int((data1_.shape[0]+(len(data1)-1)-2)/(len(data1)-1))\n",
    "    data1_[0:interval, 0] = np.linspace(data1[0], data1[1], interval)\n",
    "    for i in range(0, len(data1)-3):\n",
    "        data1_[interval+i*(interval-1):interval+i*(interval-1)+(interval-1), 0] = np.linspace(data1[i+1], data1[i+2], interval)[1: ]\n",
    "    surplus_number = data1_.shape[0]-interval-(interval - 1)*(len(data1)-3)\n",
    "    data1_[-surplus_number-1: , 0] = np.linspace(data1[-2], data1[-1], surplus_number+1)\n",
    "    return data1_\n",
    "\n",
    "def plot(title):\n",
    "    for i in range(len(list(dict_.keys()))):\n",
    "        value = dict_[list(dict_.keys())[i]]\n",
    "        dict_[list(dict_.keys())[i]] = np.array(value)\n",
    "        value = dict_[list(dict_.keys())[i]]\n",
    "        mean_ = value.mean(0) \n",
    "        std_ = value.std(0)\n",
    "        error_params=dict(elinewidth=1,ecolor='k',capsize=6)\n",
    "        width = 0.25\n",
    "        if title in list(dict_.keys())[i]: \n",
    "            if '途中' in list(dict_.keys())[i]:\n",
    "                plt.bar(x=[1-width, 2-width, 3-width, 4-width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C0',\n",
    "                       label='Midway')\n",
    "            if '加速' in list(dict_.keys())[i]:\n",
    "                plt.bar(x=[1, 2, 3, 4], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C2',\n",
    "                       label='Boost')\n",
    "            if '冲刺' in list(dict_.keys())[i]:\n",
    "                plt.bar(x=[1+width, 2+width, 3+width, 4+width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C1',\n",
    "                       label='Sprint')\n",
    "    plt.xticks([1,2,3,4],['In\\n-phase','Anti\\n-phase','A1','A2'],fontsize=16)\n",
    "    plt.yticks(fontsize=16)\n",
    "    plt.legend(fontsize=12,loc='upper right')\n",
    "    plt.ylabel('Number',fontsize=18)\n",
    "    plt.title(title, fontsize=20)\n",
    "    \n",
    "dict_ = {}\n",
    "for k in ['途中','加速','冲刺']:\n",
    "    print(k)\n",
    "    root = 'C:/code/北体数据处理/肢体角度数据/二级运动员数据/二级运动员{}段（后摆、前摆、支撑）.xlsx'.format(k)\n",
    "    wb = load_workbook(root)\n",
    "    sheets = wb.worksheets   # 获取当前所有的sheet\n",
    "    for ss in range(len(sheets)):\n",
    "        sheet1 = sheets[ss]\n",
    "        df=pd.read_excel(root,sheet_name=sheet1.title)\n",
    "        data=df.head(n=sheet1.max_row)\n",
    "        data1 = getDataFull(data, xindex=0, yindex=1)\n",
    "        data2 = getDataFull(data, xindex=0, yindex=2)\n",
    "        data3 = getDataFull(data, xindex=0, yindex=3)\n",
    "        data4 = getDataFull(data, xindex=5, yindex=6)\n",
    "        data5 = getDataFull(data, xindex=5, yindex=7)\n",
    "        data6 = getDataFull(data, xindex=5, yindex=8)\n",
    "        pair = [[1,2],[2,3],[4,5],[5,6]]\n",
    "        for i in pair:\n",
    "            str_ = ''\n",
    "            str_+=k+'_'\n",
    "            if i == [1,2]:str_+='The left hip with The left knee'\n",
    "            if i == [2,3]:str_+='The left knee with The left ankle'\n",
    "            if i == [4,5]:str_+='The right hip with The right knee'\n",
    "            if i == [5,6]:str_+='The right knee with The right ankle'\n",
    "            num_ = CA(eval('data{}'.format(i[0])), eval('data{}'.format(i[1])), 2)[:4,1]\n",
    "            if str_ not in dict_.keys():\n",
    "                dict_[str_] = []\n",
    "                dict_[str_].append(num_.tolist())\n",
    "            else:\n",
    "                dict_[str_].append(num_.tolist())\n",
    "print(dict_.keys())\n",
    "\n",
    "plot('The left hip with The left knee')\n",
    "plt.savefig('Figure/二级运动员对比（左髋关节&左膝关节）.jpg',dpi=300,bbox_inches = 'tight')\n",
    "plt.show()\n",
    "plot('The left knee with The left ankle')\n",
    "plt.savefig('Figure/二级运动员对比（左膝关节&左踝关节）.jpg',dpi=300,bbox_inches = 'tight')\n",
    "plt.show()\n",
    "plot('The right hip with The right knee')\n",
    "plt.savefig('Figure/二级运动员对比（右髋关节&右膝关节）.jpg',dpi=300,bbox_inches = 'tight')\n",
    "plt.show()\n",
    "plot('The right knee with The right ankle')\n",
    "plt.savefig('Figure/二级运动员对比（右膝关节&右踝关节）.jpg',dpi=300,bbox_inches = 'tight')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 三个阶段分开（比较途中，加速，冲刺）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from openpyxl import load_workbook\n",
    "import  pandas  as pd\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "def removeNan(data1):\n",
    "    try:\n",
    "        x = np.where(np.isnan(data1)==True)[0]\n",
    "        data1 = data1.tolist()\n",
    "        for i in range(len(x)-1,-1,-1):\n",
    "            data1.remove(data1[x[i]])\n",
    "    except:\n",
    "        data1 = data1.tolist()\n",
    "    return data1\n",
    "\n",
    "def getData(data, xindex=None, yindex=None):\n",
    "    # 获取数据\n",
    "    index1 = data[data.iloc[:,xindex]=='后摆阶段'].index.tolist()[0]\n",
    "    index2 = data[data.iloc[:,xindex]=='前摆阶段'].index.tolist()[0]\n",
    "    index3 = data[data.iloc[:,xindex]=='支撑阶段'].index.tolist()[0]\n",
    "    data1 = np.array(data.iloc[index1:index2, [yindex]]).T[0]\n",
    "    data1 = removeNan(data1)\n",
    "    data2 = np.array(data.iloc[index2:index3, [yindex]]).T[0]\n",
    "    data2 = removeNan(data2)\n",
    "    data3 = np.array(data.iloc[index3:, [yindex]]).T[0]\n",
    "    data3= removeNan(data3)\n",
    "    return lineInsert(data1), lineInsert(data2), lineInsert(data3)\n",
    "\n",
    "def getDataFull(data, xindex=None, yindex=None):\n",
    "    # 获取数据\n",
    "    index1 = data[data.iloc[:,xindex]=='后摆阶段'].index.tolist()[0]\n",
    "    index2 = data[data.iloc[:,xindex]=='前摆阶段'].index.tolist()[0]\n",
    "    index3 = data[data.iloc[:,xindex]=='支撑阶段'].index.tolist()[0]\n",
    "    data1 = np.array(data.iloc[index1:index2, [yindex]]).T[0]\n",
    "    data1 = removeNan(data1)\n",
    "    data2 = np.array(data.iloc[index2:index3, [yindex]]).T[0]\n",
    "    data2 = removeNan(data2)\n",
    "    data3 = np.array(data.iloc[index3:, [yindex]]).T[0]\n",
    "    data3= removeNan(data3)\n",
    "    data = data1+data2[1:]+data3[1:]\n",
    "    return lineInsert(data)\n",
    "\n",
    "def lineInsert(data1):\n",
    "    data1_ = np.zeros((101,1))\n",
    "    interval = int((data1_.shape[0]+(len(data1)-1)-2)/(len(data1)-1))\n",
    "    data1_[0:interval, 0] = np.linspace(data1[0], data1[1], interval)\n",
    "    for i in range(0, len(data1)-3):\n",
    "        data1_[interval+i*(interval-1):interval+i*(interval-1)+(interval-1), 0] = np.linspace(data1[i+1], data1[i+2], interval)[1: ]\n",
    "    surplus_number = data1_.shape[0]-interval-(interval - 1)*(len(data1)-3)\n",
    "    data1_[-surplus_number-1: , 0] = np.linspace(data1[-2], data1[-1], surplus_number+1)\n",
    "    return data1_\n",
    "\n",
    "dict_ = {}\n",
    "for k in ['途中','加速','冲刺']:\n",
    "    root = 'C:/code/北体数据处理/肢体角度数据/二级运动员数据/二级运动员{}段（后摆、前摆、支撑）.xlsx'.format(k)\n",
    "    wb = load_workbook(root)\n",
    "    sheets = wb.worksheets   # 获取当前所有的sheet\n",
    "    for ss in range(len(sheets)):\n",
    "        sheet1 = sheets[ss]\n",
    "        df=pd.read_excel(root,sheet_name=sheet1.title)\n",
    "        data=df.head(n=sheet1.max_row)\n",
    "        data1_1, data1_2, data1_3 = getData(data, xindex=0, yindex=1) # 读取所有数据\n",
    "        data2_1, data2_2, data2_3 = getData(data, xindex=0, yindex=2)\n",
    "        data3_1, data3_2, data3_3 = getData(data, xindex=0, yindex=3)\n",
    "        data4_1, data4_2, data4_3 = getData(data, xindex=5, yindex=6)\n",
    "        data5_1, data5_2, data5_3 = getData(data, xindex=5, yindex=7)\n",
    "        data6_1, data6_2, data6_3 = getData(data, xindex=5, yindex=8)\n",
    "        pair = [[1,2],[2,3],[4,5],[5,6]]\n",
    "        for i in pair:\n",
    "            for j in range(1,4):\n",
    "                str_ = ''\n",
    "                str_+=k+'_'\n",
    "                if i == [1,2]:str_+='The left hip with The left knee'\n",
    "                if i == [2,3]:str_+='The left knee with The left ankle'\n",
    "                if i == [4,5]:str_+='The right hip with The right knee'\n",
    "                if i == [5,6]:str_+='The right knee with The right ankle'\n",
    "                if j == 1: str_+=' in\\n The phase of swinging back_1'\n",
    "                if j == 2: str_+=' in\\n The phase of swinging forward_2'\n",
    "                if j == 3: str_+=' in\\n The phase of support_3'\n",
    "                num_ = CA(eval('data{}_{}'.format(i[0], j)), eval('data{}_{}'.format(i[1], j)), 2)[:4,1]\n",
    "                if str_ not in dict_.keys():\n",
    "                    dict_[str_] = []\n",
    "                    dict_[str_].append(num_.tolist())\n",
    "                else:\n",
    "                    dict_[str_].append(num_.tolist())\n",
    "# print(dict_.keys())\n",
    "\n",
    "def plot(title,phase):\n",
    "    for i in range(len(list(dict_.keys()))):\n",
    "        value = dict_[list(dict_.keys())[i]]\n",
    "        dict_[list(dict_.keys())[i]] = np.array(value)\n",
    "        value = dict_[list(dict_.keys())[i]]\n",
    "        mean_ = value.mean(0) \n",
    "        std_ = value.std(0)\n",
    "        error_params=dict(elinewidth=1,ecolor='k',capsize=6)\n",
    "        width = 0.25\n",
    "        if title in list(dict_.keys())[i]: \n",
    "            if phase in list(dict_.keys())[i]:\n",
    "                print(list(dict_.keys())[i])\n",
    "                if '途中' in list(dict_.keys())[i]:\n",
    "                    plt.bar(x=[1-width, 2-width, 3-width, 4-width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C0',\n",
    "                           label='Midway')\n",
    "                if '加速' in list(dict_.keys())[i]:\n",
    "                    plt.bar(x=[1, 2, 3, 4], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C2',\n",
    "                           label='Boost')\n",
    "                if '冲刺' in list(dict_.keys())[i]:\n",
    "                    plt.bar(x=[1+width, 2+width, 3+width, 4+width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C1',\n",
    "                           label='Sprint')\n",
    "    plt.xticks([1,2,3,4],['In\\n-phase','Anti\\n-phase','A1','A2'],fontsize=16)\n",
    "    plt.yticks(fontsize=16)\n",
    "    plt.legend(fontsize=12,loc='upper right')\n",
    "    plt.ylabel('Number',fontsize=18)\n",
    "    if phase == '1': title+=' in\\n The phase of swinging back'\n",
    "    if phase == '2': title+=' in\\n The phase of swinging forward'\n",
    "    if phase == '3': title+=' in\\n The phase of support'\n",
    "    plt.title(title, fontsize=20)\n",
    "\n",
    "for i in range(1,4):\n",
    "    plot('The left hip with The left knee', '{}'.format(i))\n",
    "    plt.savefig('Figure/二级运动员对比（左髋关节&左膝关节）_{}.jpg'.format(i),dpi=300,bbox_inches = 'tight')\n",
    "    plt.show()\n",
    "    plot('The left knee with The left ankle', '{}'.format(i))\n",
    "    plt.savefig('Figure/二级运动员对比（左膝关节&左踝关节）_{}.jpg'.format(i),dpi=300,bbox_inches = 'tight')\n",
    "    plt.show()\n",
    "    plot('The right hip with The right knee', '{}'.format(i))\n",
    "    plt.savefig('Figure/二级运动员对比（右髋关节&右膝关节）_{}.jpg'.format(i),dpi=300,bbox_inches = 'tight')\n",
    "    plt.show()\n",
    "    plot('The right knee with The right ankle', '{}'.format(i))\n",
    "    plt.savefig('Figure/二级运动员对比（右膝关节&右踝关节）_{}.jpg'.format(i),dpi=300,bbox_inches = 'tight')\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 三个阶段分开（比较前摆，后摆，支撑）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "from openpyxl import load_workbook\n",
    "import  pandas  as pd\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "def removeNan(data1):\n",
    "    try:\n",
    "        x = np.where(np.isnan(data1)==True)[0]\n",
    "        data1 = data1.tolist()\n",
    "        for i in range(len(x)-1,-1,-1):\n",
    "            data1.remove(data1[x[i]])\n",
    "    except:\n",
    "        data1 = data1.tolist()\n",
    "    return data1\n",
    "\n",
    "def getData(data, xindex=None, yindex=None):\n",
    "    # 获取数据\n",
    "    index1 = data[data.iloc[:,xindex]=='后摆阶段'].index.tolist()[0]\n",
    "    index2 = data[data.iloc[:,xindex]=='前摆阶段'].index.tolist()[0]\n",
    "    index3 = data[data.iloc[:,xindex]=='支撑阶段'].index.tolist()[0]\n",
    "    data1 = np.array(data.iloc[index1:index2, [yindex]]).T[0]\n",
    "    data1 = removeNan(data1)\n",
    "    data2 = np.array(data.iloc[index2:index3, [yindex]]).T[0]\n",
    "    data2 = removeNan(data2)\n",
    "    data3 = np.array(data.iloc[index3:, [yindex]]).T[0]\n",
    "    data3= removeNan(data3)\n",
    "    return lineInsert(data1), lineInsert(data2), lineInsert(data3)\n",
    "\n",
    "def getDataFull(data, xindex=None, yindex=None):\n",
    "    # 获取数据\n",
    "    index1 = data[data.iloc[:,xindex]=='后摆阶段'].index.tolist()[0]\n",
    "    index2 = data[data.iloc[:,xindex]=='前摆阶段'].index.tolist()[0]\n",
    "    index3 = data[data.iloc[:,xindex]=='支撑阶段'].index.tolist()[0]\n",
    "    data1 = np.array(data.iloc[index1:index2, [yindex]]).T[0]\n",
    "    data1 = removeNan(data1)\n",
    "    data2 = np.array(data.iloc[index2:index3, [yindex]]).T[0]\n",
    "    data2 = removeNan(data2)\n",
    "    data3 = np.array(data.iloc[index3:, [yindex]]).T[0]\n",
    "    data3= removeNan(data3)\n",
    "    data = data1+data2[1:]+data3[1:]\n",
    "    return lineInsert(data)\n",
    "\n",
    "def lineInsert(data1):\n",
    "    data1_ = np.zeros((101,1))\n",
    "    interval = int((data1_.shape[0]+(len(data1)-1)-2)/(len(data1)-1))\n",
    "    data1_[0:interval, 0] = np.linspace(data1[0], data1[1], interval)\n",
    "    for i in range(0, len(data1)-3):\n",
    "        data1_[interval+i*(interval-1):interval+i*(interval-1)+(interval-1), 0] = np.linspace(data1[i+1], data1[i+2], interval)[1: ]\n",
    "    surplus_number = data1_.shape[0]-interval-(interval - 1)*(len(data1)-3)\n",
    "    data1_[-surplus_number-1: , 0] = np.linspace(data1[-2], data1[-1], surplus_number+1)\n",
    "    return data1_\n",
    "\n",
    "dict_ = {}\n",
    "for k in ['途中','加速','冲刺']:\n",
    "    root = 'C:/code/北体数据处理/肢体角度数据/二级运动员数据/二级运动员{}段（后摆、前摆、支撑）.xlsx'.format(k)\n",
    "    wb = load_workbook(root)\n",
    "    sheets = wb.worksheets   # 获取当前所有的sheet\n",
    "    for ss in range(len(sheets)):\n",
    "        sheet1 = sheets[ss]\n",
    "        df=pd.read_excel(root,sheet_name=sheet1.title)\n",
    "        data=df.head(n=sheet1.max_row)\n",
    "        data1_1, data1_2, data1_3 = getData(data, xindex=0, yindex=1) # 读取所有数据\n",
    "        data2_1, data2_2, data2_3 = getData(data, xindex=0, yindex=2)\n",
    "        data3_1, data3_2, data3_3 = getData(data, xindex=0, yindex=3)\n",
    "        data4_1, data4_2, data4_3 = getData(data, xindex=5, yindex=6)\n",
    "        data5_1, data5_2, data5_3 = getData(data, xindex=5, yindex=7)\n",
    "        data6_1, data6_2, data6_3 = getData(data, xindex=5, yindex=8)\n",
    "        pair = [[1,2],[2,3],[4,5],[5,6]]\n",
    "        for i in pair:\n",
    "            for j in range(1,4):\n",
    "                str_ = ''\n",
    "                str_+=k+'_'\n",
    "                if i == [1,2]:str_+='The left hip with The left knee'\n",
    "                if i == [2,3]:str_+='The left knee with The left ankle'\n",
    "                if i == [4,5]:str_+='The right hip with The right knee'\n",
    "                if i == [5,6]:str_+='The right knee with The right ankle'\n",
    "                if j == 1: str_+=' in\\n The phase of swinging back_1'\n",
    "                if j == 2: str_+=' in\\n The phase of swinging forward_2'\n",
    "                if j == 3: str_+=' in\\n The phase of support_3'\n",
    "                num_ = CA(eval('data{}_{}'.format(i[0], j)), eval('data{}_{}'.format(i[1], j)), 2)[:4,1]\n",
    "                if str_ not in dict_.keys():\n",
    "                    dict_[str_] = []\n",
    "                    dict_[str_].append(num_.tolist())\n",
    "                else:\n",
    "                    dict_[str_].append(num_.tolist())\n",
    "print(dict_.keys())\n",
    "\n",
    "def plot(title,phase):\n",
    "    for i in range(len(list(dict_.keys()))):\n",
    "        value = dict_[list(dict_.keys())[i]]\n",
    "        dict_[list(dict_.keys())[i]] = np.array(value)\n",
    "        value = dict_[list(dict_.keys())[i]]\n",
    "        mean_ = value.mean(0) \n",
    "        std_ = value.std(0)\n",
    "        error_params=dict(elinewidth=1,ecolor='k',capsize=6)\n",
    "        width = 0.25\n",
    "        if title in list(dict_.keys())[i]: \n",
    "            if '途中' in list(dict_.keys())[i] and phase=='1':\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '1':\n",
    "                    plt.bar(x=[1-width, 2-width, 3-width, 4-width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C0',\n",
    "                           label='Swinging back')\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '2':\n",
    "                    plt.bar(x=[1, 2, 3, 4], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C2',\n",
    "                           label='Swinging forward')\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '3':\n",
    "                    plt.bar(x=[1+width, 2+width, 3+width, 4+width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C1',\n",
    "                           label='Support')\n",
    "            if '加速' in list(dict_.keys())[i] and phase=='2':\n",
    "                print('ssss')\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '1':\n",
    "                    plt.bar(x=[1-width, 2-width, 3-width, 4-width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C0',\n",
    "                           label='Swinging back')\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '2':\n",
    "                    plt.bar(x=[1, 2, 3, 4], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C2',\n",
    "                           label='Swinging forward')\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '3':\n",
    "                    plt.bar(x=[1+width, 2+width, 3+width, 4+width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C1',\n",
    "                           label='Support')\n",
    "            if '冲刺' in list(dict_.keys())[i] and phase=='3':\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '1':\n",
    "                    plt.bar(x=[1-width, 2-width, 3-width, 4-width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C0',\n",
    "                           label='Swinging back')\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '2':\n",
    "                    plt.bar(x=[1, 2, 3, 4], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C2',\n",
    "                           label='Swinging forward')\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '3':\n",
    "                    plt.bar(x=[1+width, 2+width, 3+width, 4+width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C1',\n",
    "                           label='Support')\n",
    "    plt.xticks([1,2,3,4],['In\\n-phase','Anti\\n-phase','A1','A2'],fontsize=16)\n",
    "    plt.yticks(fontsize=16)\n",
    "    plt.legend(fontsize=12,loc='upper right')\n",
    "    plt.ylabel('Number',fontsize=18)\n",
    "    if phase == '1': title+=' \\nin Midway'\n",
    "    if phase == '2': title+=' \\nin Boost'\n",
    "    if phase == '3': title+=' \\nin Sprint'\n",
    "    plt.title(title, fontsize=20)\n",
    "\n",
    "for i in range(1,4):\n",
    "    plot('The left hip with The left knee', '{}'.format(i))\n",
    "    plt.savefig('Figure/二级运动员对比（左髋关节&左膝关节）_{}_s.jpg'.format(i),dpi=300,bbox_inches = 'tight')\n",
    "    plt.show()\n",
    "    plot('The left knee with The left ankle', '{}'.format(i))\n",
    "    plt.savefig('Figure/二级运动员对比（左膝关节&左踝关节）_{}_s.jpg'.format(i),dpi=300,bbox_inches = 'tight')\n",
    "    plt.show()\n",
    "    plot('The right hip with The right knee', '{}'.format(i))\n",
    "    plt.savefig('Figure/二级运动员对比（右髋关节&右膝关节）_{}_s.jpg'.format(i),dpi=300,bbox_inches = 'tight')\n",
    "    plt.show()\n",
    "    plot('The right knee with The right ankle', '{}'.format(i))\n",
    "    plt.savefig('Figure/二级运动员对比（右膝关节&右踝关节）_{}_s.jpg'.format(i),dpi=300,bbox_inches = 'tight')\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 健将运动员途中，加速，冲刺对比"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "from openpyxl import load_workbook\n",
    "import  pandas  as pd\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "# {'左髋关节':1, '左膝关节':2, '左踝关节':3, '右髋关节':7, '右膝关节':8, '右踝关节':9}\n",
    "# def getData(data, xindex=None, yindex=None):\n",
    "#     # 获取数据\n",
    "#     index1 = data[data.iloc[:,xindex]=='后摆阶段'].index.tolist()[0]\n",
    "#     index2 = data[data.iloc[:,xindex]=='前摆阶段'].index.tolist()[0]\n",
    "#     index3 = data[data.iloc[:,xindex]=='支撑阶段'].index.tolist()[0]\n",
    "#     data1 = np.array(data.iloc[index1:index2, [yindex]]).T[0]\n",
    "#     data2 = np.array(data.iloc[index2:index3, [yindex]]).T[0]\n",
    "#     data3 = np.array(data.iloc[index3:, [yindex]])\n",
    "#     print(lineInsert(data1))\n",
    "#     try:\n",
    "#         x = np.where(np.isnan(data3)==True)[0][0]\n",
    "#         data3 = np.array(data3.tolist()[:x]).T[0]\n",
    "#     except:\n",
    "#         data3 = np.array(data.iloc[index3:, [yindex]]).T[0]\n",
    "#     return lineInsert(data1), lineInsert(data2), lineInsert(data3)\n",
    "\n",
    "def removeNan(data1):\n",
    "    try:\n",
    "        x = np.where(np.isnan(data1)==True)[0]\n",
    "        data1 = data1.tolist()\n",
    "        for i in range(len(x)-1,-1,-1):\n",
    "            data1.remove(data1[x[i]])\n",
    "    except:\n",
    "        data1 = data1.tolist()\n",
    "    return data1\n",
    "\n",
    "def getData(data, xindex=None, yindex=None):\n",
    "    # 获取数据\n",
    "    index1 = data[data.iloc[:,xindex]=='后摆阶段'].index.tolist()[0]\n",
    "    index2 = data[data.iloc[:,xindex]=='前摆阶段'].index.tolist()[0]\n",
    "    index3 = data[data.iloc[:,xindex]=='支撑阶段'].index.tolist()[0]\n",
    "    data1 = np.array(data.iloc[index1:index2, [yindex]]).T[0]\n",
    "    data1 = removeNan(data1)\n",
    "    data2 = np.array(data.iloc[index2:index3, [yindex]]).T[0]\n",
    "    data2 = removeNan(data2)\n",
    "    data3 = np.array(data.iloc[index3:, [yindex]]).T[0]\n",
    "    data3= removeNan(data3)\n",
    "    return lineInsert(data1), lineInsert(data2), lineInsert(data3)\n",
    "\n",
    "def getDataFull(data, xindex=None, yindex=None):\n",
    "    # 获取数据\n",
    "    index1 = data[data.iloc[:,xindex]=='后摆阶段'].index.tolist()[0]\n",
    "    index2 = data[data.iloc[:,xindex]=='前摆阶段'].index.tolist()[0]\n",
    "    index3 = data[data.iloc[:,xindex]=='支撑阶段'].index.tolist()[0]\n",
    "    data1 = np.array(data.iloc[index1:index2, [yindex]]).T[0]\n",
    "    data1 = removeNan(data1)\n",
    "    data2 = np.array(data.iloc[index2:index3, [yindex]]).T[0]\n",
    "    data2 = removeNan(data2)\n",
    "    data3 = np.array(data.iloc[index3:, [yindex]]).T[0]\n",
    "    data3= removeNan(data3)\n",
    "    data = data1+data2[1:]+data3[1:]\n",
    "    return lineInsert(data)\n",
    "\n",
    "def lineInsert(data1):\n",
    "    data1_ = np.zeros((101,1))\n",
    "    interval = int((data1_.shape[0]+(len(data1)-1)-2)/(len(data1)-1))\n",
    "    data1_[0:interval, 0] = np.linspace(data1[0], data1[1], interval)\n",
    "    for i in range(0, len(data1)-3):\n",
    "        data1_[interval+i*(interval-1):interval+i*(interval-1)+(interval-1), 0] = np.linspace(data1[i+1], data1[i+2], interval)[1: ]\n",
    "    surplus_number = data1_.shape[0]-interval-(interval - 1)*(len(data1)-3)\n",
    "    data1_[-surplus_number-1: , 0] = np.linspace(data1[-2], data1[-1], surplus_number+1)\n",
    "    return data1_\n",
    "\n",
    "dict_ = {}\n",
    "for k in ['途中','加速','冲刺']:\n",
    "    print(k)\n",
    "    root = 'C:/code/北体数据处理/肢体角度数据/健将运动员数据/健将运动员{}阶段数据.xlsx'.format(k)\n",
    "    wb = load_workbook(root)\n",
    "    sheets = wb.worksheets   # 获取当前所有的sheet\n",
    "    for ss in range(len(sheets)):\n",
    "        sheet1 = sheets[ss]\n",
    "        df=pd.read_excel(root,sheet_name=sheet1.title)\n",
    "        data=df.head(n=sheet1.max_row)\n",
    "        data1 = getDataFull(data, xindex=0, yindex=1)\n",
    "        data2 = getDataFull(data, xindex=0, yindex=2)\n",
    "        data3 = getDataFull(data, xindex=0, yindex=3)\n",
    "        data4 = getDataFull(data, xindex=6, yindex=7)\n",
    "        data5 = getDataFull(data, xindex=6, yindex=8)\n",
    "        data6 = getDataFull(data, xindex=6, yindex=9)\n",
    "        pair = [[1,2],[2,3],[4,5],[5,6]]\n",
    "        for i in pair:\n",
    "            str_ = ''\n",
    "            str_+=k+'_'\n",
    "            if i == [1,2]:str_+='The left hip with The left knee'\n",
    "            if i == [2,3]:str_+='The left knee with The left ankle'\n",
    "            if i == [4,5]:str_+='The right hip with The right knee'\n",
    "            if i == [5,6]:str_+='The right knee with The right ankle'\n",
    "            num_ = CA(eval('data{}'.format(i[0])), eval('data{}'.format(i[1])), 2)[:4,1]\n",
    "            if str_ not in dict_.keys():\n",
    "                dict_[str_] = []\n",
    "                dict_[str_].append(num_.tolist())\n",
    "            else:\n",
    "                dict_[str_].append(num_.tolist())\n",
    "print(dict_.keys())\n",
    "\n",
    "def plot(title):\n",
    "    for i in range(len(list(dict_.keys()))):\n",
    "        value = dict_[list(dict_.keys())[i]]\n",
    "        dict_[list(dict_.keys())[i]] = np.array(value)\n",
    "        value = dict_[list(dict_.keys())[i]]\n",
    "        mean_ = value.mean(0) \n",
    "        std_ = value.std(0)\n",
    "        error_params=dict(elinewidth=1,ecolor='k',capsize=6)\n",
    "        width = 0.25\n",
    "        if title in list(dict_.keys())[i]: \n",
    "            if '途中' in list(dict_.keys())[i]:\n",
    "                plt.bar(x=[1-width, 2-width, 3-width, 4-width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C0',\n",
    "                       label='Midway')\n",
    "            if '加速' in list(dict_.keys())[i]:\n",
    "                plt.bar(x=[1, 2, 3, 4], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C2',\n",
    "                       label='Boost')\n",
    "            if '冲刺' in list(dict_.keys())[i]:\n",
    "                plt.bar(x=[1+width, 2+width, 3+width, 4+width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C1',\n",
    "                       label='Sprint')\n",
    "    plt.xticks([1,2,3,4],['In\\n-phase','Anti\\n-phase','A1','A2'],fontsize=16)\n",
    "    plt.yticks(fontsize=16)\n",
    "    plt.legend(fontsize=12,loc='upper right')\n",
    "    plt.ylabel('Number',fontsize=18)\n",
    "    plt.title(title, fontsize=20)\n",
    "\n",
    "\n",
    "plot('The left hip with The left knee')\n",
    "plt.savefig('Figure/健将运动员对比（左髋关节&左膝关节）.jpg',dpi=300,bbox_inches = 'tight')\n",
    "plt.show()\n",
    "plot('The left knee with The left ankle')\n",
    "plt.savefig('Figure/健将运动员对比（左膝关节&左踝关节）.jpg',dpi=300,bbox_inches = 'tight')\n",
    "plt.show()\n",
    "plot('The right hip with The right knee')\n",
    "plt.savefig('Figure/健将运动员对比（右髋关节&右膝关节）.jpg',dpi=300,bbox_inches = 'tight')\n",
    "plt.show()\n",
    "plot('The right knee with The right ankle')\n",
    "plt.savefig('Figure/健将运动员对比（右膝关节&右踝关节）.jpg',dpi=300,bbox_inches = 'tight')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 三个阶段分开（比较途中，加速，冲刺）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from openpyxl import load_workbook\n",
    "import  pandas  as pd\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "def removeNan(data1):\n",
    "    try:\n",
    "        x = np.where(np.isnan(data1)==True)[0]\n",
    "        data1 = data1.tolist()\n",
    "        for i in range(len(x)-1,-1,-1):\n",
    "            data1.remove(data1[x[i]])\n",
    "    except:\n",
    "        data1 = data1.tolist()\n",
    "    return data1\n",
    "\n",
    "def getData(data, xindex=None, yindex=None):\n",
    "    # 获取数据\n",
    "    index1 = data[data.iloc[:,xindex]=='后摆阶段'].index.tolist()[0]\n",
    "    index2 = data[data.iloc[:,xindex]=='前摆阶段'].index.tolist()[0]\n",
    "    index3 = data[data.iloc[:,xindex]=='支撑阶段'].index.tolist()[0]\n",
    "    data1 = np.array(data.iloc[index1:index2, [yindex]]).T[0]\n",
    "    data1 = removeNan(data1)\n",
    "    data2 = np.array(data.iloc[index2:index3, [yindex]]).T[0]\n",
    "    data2 = removeNan(data2)\n",
    "    data3 = np.array(data.iloc[index3:, [yindex]]).T[0]\n",
    "    data3= removeNan(data3)\n",
    "    return lineInsert(data1), lineInsert(data2), lineInsert(data3)\n",
    "\n",
    "def getDataFull(data, xindex=None, yindex=None):\n",
    "    # 获取数据\n",
    "    index1 = data[data.iloc[:,xindex]=='后摆阶段'].index.tolist()[0]\n",
    "    index2 = data[data.iloc[:,xindex]=='前摆阶段'].index.tolist()[0]\n",
    "    index3 = data[data.iloc[:,xindex]=='支撑阶段'].index.tolist()[0]\n",
    "    data1 = np.array(data.iloc[index1:index2, [yindex]]).T[0]\n",
    "    data1 = removeNan(data1)\n",
    "    data2 = np.array(data.iloc[index2:index3, [yindex]]).T[0]\n",
    "    data2 = removeNan(data2)\n",
    "    data3 = np.array(data.iloc[index3:, [yindex]]).T[0]\n",
    "    data3= removeNan(data3)\n",
    "    data = data1+data2[1:]+data3[1:]\n",
    "    return lineInsert(data)\n",
    "\n",
    "def lineInsert(data1):\n",
    "    data1_ = np.zeros((101,1))\n",
    "    interval = int((data1_.shape[0]+(len(data1)-1)-2)/(len(data1)-1))\n",
    "    data1_[0:interval, 0] = np.linspace(data1[0], data1[1], interval)\n",
    "    for i in range(0, len(data1)-3):\n",
    "        data1_[interval+i*(interval-1):interval+i*(interval-1)+(interval-1), 0] = np.linspace(data1[i+1], data1[i+2], interval)[1: ]\n",
    "    surplus_number = data1_.shape[0]-interval-(interval - 1)*(len(data1)-3)\n",
    "    data1_[-surplus_number-1: , 0] = np.linspace(data1[-2], data1[-1], surplus_number+1)\n",
    "    return data1_\n",
    "\n",
    "dict_ = {}\n",
    "for k in ['途中','加速','冲刺']:\n",
    "    root = 'C:/code/北体数据处理/肢体角度数据/健将运动员数据/健将运动员{}阶段数据.xlsx'.format(k)\n",
    "    wb = load_workbook(root)\n",
    "    sheets = wb.worksheets   # 获取当前所有的sheet\n",
    "    for ss in range(len(sheets)):\n",
    "        sheet1 = sheets[ss]\n",
    "        df=pd.read_excel(root,sheet_name=sheet1.title)\n",
    "        data=df.head(n=sheet1.max_row)\n",
    "        data1_1, data1_2, data1_3 = getData(data, xindex=0, yindex=1) # 读取所有数据\n",
    "        data2_1, data2_2, data2_3 = getData(data, xindex=0, yindex=2)\n",
    "        data3_1, data3_2, data3_3 = getData(data, xindex=0, yindex=3)\n",
    "        data4_1, data4_2, data4_3 = getData(data, xindex=6, yindex=7)\n",
    "        data5_1, data5_2, data5_3 = getData(data, xindex=6, yindex=8)\n",
    "        data6_1, data6_2, data6_3 = getData(data, xindex=6, yindex=9)\n",
    "        pair = [[1,2],[2,3],[4,5],[5,6]]\n",
    "        for i in pair:\n",
    "            for j in range(1,4):\n",
    "                str_ = ''\n",
    "                str_+=k+'_'\n",
    "                if i == [1,2]:str_+='The left hip with The left knee'\n",
    "                if i == [2,3]:str_+='The left knee with The left ankle'\n",
    "                if i == [4,5]:str_+='The right hip with The right knee'\n",
    "                if i == [5,6]:str_+='The right knee with The right ankle'\n",
    "                if j == 1: str_+=' in\\n The phase of swinging back_1'\n",
    "                if j == 2: str_+=' in\\n The phase of swinging forward_2'\n",
    "                if j == 3: str_+=' in\\n The phase of support_3'\n",
    "                num_ = CA(eval('data{}_{}'.format(i[0], j)), eval('data{}_{}'.format(i[1], j)), 2)[:4,1]\n",
    "                if str_ not in dict_.keys():\n",
    "                    dict_[str_] = []\n",
    "                    dict_[str_].append(num_.tolist())\n",
    "                else:\n",
    "                    dict_[str_].append(num_.tolist())\n",
    "# print(dict_.keys())\n",
    "\n",
    "def plot(title,phase):\n",
    "    for i in range(len(list(dict_.keys()))):\n",
    "        value = dict_[list(dict_.keys())[i]]\n",
    "        dict_[list(dict_.keys())[i]] = np.array(value)\n",
    "        value = dict_[list(dict_.keys())[i]]\n",
    "        mean_ = value.mean(0) \n",
    "        std_ = value.std(0)\n",
    "        error_params=dict(elinewidth=1,ecolor='k',capsize=6)\n",
    "        width = 0.25\n",
    "        if title in list(dict_.keys())[i]: \n",
    "            if phase in list(dict_.keys())[i]:\n",
    "                print(list(dict_.keys())[i])\n",
    "                if '途中' in list(dict_.keys())[i]:\n",
    "                    plt.bar(x=[1-width, 2-width, 3-width, 4-width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C0',\n",
    "                           label='Midway')\n",
    "                if '加速' in list(dict_.keys())[i]:\n",
    "                    plt.bar(x=[1, 2, 3, 4], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C2',\n",
    "                           label='Boost')\n",
    "                if '冲刺' in list(dict_.keys())[i]:\n",
    "                    plt.bar(x=[1+width, 2+width, 3+width, 4+width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C1',\n",
    "                           label='Sprint')\n",
    "    plt.xticks([1,2,3,4],['In\\n-phase','Anti\\n-phase','A1','A2'],fontsize=16)\n",
    "    plt.yticks(fontsize=16)\n",
    "    plt.legend(fontsize=12,loc='upper right')\n",
    "    plt.ylabel('Number',fontsize=18)\n",
    "    if phase == '1': title+=' in\\n The phase of swinging back'\n",
    "    if phase == '2': title+=' in\\n The phase of swinging forward'\n",
    "    if phase == '3': title+=' in\\n The phase of support'\n",
    "    plt.title(title, fontsize=20)\n",
    "\n",
    "for i in range(1,4):\n",
    "    plot('The left hip with The left knee', '{}'.format(i))\n",
    "    plt.savefig('Figure/健将运动员对比（左髋关节&左膝关节）_{}.jpg'.format(i),dpi=300,bbox_inches = 'tight')\n",
    "    plt.show()\n",
    "    plot('The left knee with The left ankle', '{}'.format(i))\n",
    "    plt.savefig('Figure/健将运动员对比（左膝关节&左踝关节）_{}.jpg'.format(i),dpi=300,bbox_inches = 'tight')\n",
    "    plt.show()\n",
    "    plot('The right hip with The right knee', '{}'.format(i))\n",
    "    plt.savefig('Figure/健将运动员对比（右髋关节&右膝关节）_{}.jpg'.format(i),dpi=300,bbox_inches = 'tight')\n",
    "    plt.show()\n",
    "    plot('The right knee with The right ankle', '{}'.format(i))\n",
    "    plt.savefig('Figure/健将运动员对比（右膝关节&右踝关节）_{}.jpg'.format(i),dpi=300,bbox_inches = 'tight')\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 三个阶段分开（比较前摆，后摆，支撑）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from openpyxl import load_workbook\n",
    "import  pandas  as pd\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "def removeNan(data1):\n",
    "    try:\n",
    "        x = np.where(np.isnan(data1)==True)[0]\n",
    "        data1 = data1.tolist()\n",
    "        for i in range(len(x)-1,-1,-1):\n",
    "            data1.remove(data1[x[i]])\n",
    "    except:\n",
    "        data1 = data1.tolist()\n",
    "    return data1\n",
    "\n",
    "def getData(data, xindex=None, yindex=None):\n",
    "    # 获取数据\n",
    "    index1 = data[data.iloc[:,xindex]=='后摆阶段'].index.tolist()[0]\n",
    "    index2 = data[data.iloc[:,xindex]=='前摆阶段'].index.tolist()[0]\n",
    "    index3 = data[data.iloc[:,xindex]=='支撑阶段'].index.tolist()[0]\n",
    "    data1 = np.array(data.iloc[index1:index2, [yindex]]).T[0]\n",
    "    data1 = removeNan(data1)\n",
    "    data2 = np.array(data.iloc[index2:index3, [yindex]]).T[0]\n",
    "    data2 = removeNan(data2)\n",
    "    data3 = np.array(data.iloc[index3:, [yindex]]).T[0]\n",
    "    data3= removeNan(data3)\n",
    "    return lineInsert(data1), lineInsert(data2), lineInsert(data3)\n",
    "\n",
    "def getDataFull(data, xindex=None, yindex=None):\n",
    "    # 获取数据\n",
    "    index1 = data[data.iloc[:,xindex]=='后摆阶段'].index.tolist()[0]\n",
    "    index2 = data[data.iloc[:,xindex]=='前摆阶段'].index.tolist()[0]\n",
    "    index3 = data[data.iloc[:,xindex]=='支撑阶段'].index.tolist()[0]\n",
    "    data1 = np.array(data.iloc[index1:index2, [yindex]]).T[0]\n",
    "    data1 = removeNan(data1)\n",
    "    data2 = np.array(data.iloc[index2:index3, [yindex]]).T[0]\n",
    "    data2 = removeNan(data2)\n",
    "    data3 = np.array(data.iloc[index3:, [yindex]]).T[0]\n",
    "    data3= removeNan(data3)\n",
    "    data = data1+data2[1:]+data3[1:]\n",
    "    return lineInsert(data)\n",
    "\n",
    "def lineInsert(data1):\n",
    "    data1_ = np.zeros((101,1))\n",
    "    interval = int((data1_.shape[0]+(len(data1)-1)-2)/(len(data1)-1))\n",
    "    data1_[0:interval, 0] = np.linspace(data1[0], data1[1], interval)\n",
    "    for i in range(0, len(data1)-3):\n",
    "        data1_[interval+i*(interval-1):interval+i*(interval-1)+(interval-1), 0] = np.linspace(data1[i+1], data1[i+2], interval)[1: ]\n",
    "    surplus_number = data1_.shape[0]-interval-(interval - 1)*(len(data1)-3)\n",
    "    data1_[-surplus_number-1: , 0] = np.linspace(data1[-2], data1[-1], surplus_number+1)\n",
    "    return data1_\n",
    "\n",
    "dict_ = {}\n",
    "for k in ['途中','加速','冲刺']:\n",
    "    root = 'C:/code/北体数据处理/肢体角度数据/健将运动员数据/健将运动员{}阶段数据.xlsx'.format(k)\n",
    "    wb = load_workbook(root)\n",
    "    sheets = wb.worksheets   # 获取当前所有的sheet\n",
    "    for ss in range(len(sheets)):\n",
    "        sheet1 = sheets[ss]\n",
    "        df=pd.read_excel(root,sheet_name=sheet1.title)\n",
    "        data=df.head(n=sheet1.max_row)\n",
    "        data1_1, data1_2, data1_3 = getData(data, xindex=0, yindex=1) # 读取所有数据\n",
    "        data2_1, data2_2, data2_3 = getData(data, xindex=0, yindex=2)\n",
    "        data3_1, data3_2, data3_3 = getData(data, xindex=0, yindex=3)\n",
    "        data4_1, data4_2, data4_3 = getData(data, xindex=6, yindex=7)\n",
    "        data5_1, data5_2, data5_3 = getData(data, xindex=6, yindex=8)\n",
    "        data6_1, data6_2, data6_3 = getData(data, xindex=6, yindex=9)\n",
    "        pair = [[1,2],[2,3],[4,5],[5,6]]\n",
    "        for i in pair:\n",
    "            for j in range(1,4):\n",
    "                str_ = ''\n",
    "                str_+=k+'_'\n",
    "                if i == [1,2]:str_+='The left hip with The left knee'\n",
    "                if i == [2,3]:str_+='The left knee with The left ankle'\n",
    "                if i == [4,5]:str_+='The right hip with The right knee'\n",
    "                if i == [5,6]:str_+='The right knee with The right ankle'\n",
    "                if j == 1: str_+=' in\\n The phase of swinging back_1'\n",
    "                if j == 2: str_+=' in\\n The phase of swinging forward_2'\n",
    "                if j == 3: str_+=' in\\n The phase of support_3'\n",
    "                num_ = CA(eval('data{}_{}'.format(i[0], j)), eval('data{}_{}'.format(i[1], j)), 2)[:4,1]\n",
    "                if str_ not in dict_.keys():\n",
    "                    dict_[str_] = []\n",
    "                    dict_[str_].append(num_.tolist())\n",
    "                else:\n",
    "                    dict_[str_].append(num_.tolist())\n",
    "print(dict_.keys())\n",
    "\n",
    "def plot(title,phase):\n",
    "    for i in range(len(list(dict_.keys()))):\n",
    "        value = dict_[list(dict_.keys())[i]]\n",
    "        dict_[list(dict_.keys())[i]] = np.array(value)\n",
    "        value = dict_[list(dict_.keys())[i]]\n",
    "        mean_ = value.mean(0) \n",
    "        std_ = value.std(0)\n",
    "        error_params=dict(elinewidth=1,ecolor='k',capsize=6)\n",
    "        width = 0.25\n",
    "        if title in list(dict_.keys())[i]: \n",
    "            if '途中' in list(dict_.keys())[i] and phase=='1':\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '1':\n",
    "                    plt.bar(x=[1-width, 2-width, 3-width, 4-width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C0',\n",
    "                           label='Swinging back')\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '2':\n",
    "                    plt.bar(x=[1, 2, 3, 4], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C2',\n",
    "                           label='Swinging forward')\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '3':\n",
    "                    plt.bar(x=[1+width, 2+width, 3+width, 4+width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C1',\n",
    "                           label='Support')\n",
    "            if '加速' in list(dict_.keys())[i] and phase=='2':\n",
    "                print('ssss')\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '1':\n",
    "                    plt.bar(x=[1-width, 2-width, 3-width, 4-width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C0',\n",
    "                           label='Swinging back')\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '2':\n",
    "                    plt.bar(x=[1, 2, 3, 4], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C2',\n",
    "                           label='Swinging forward')\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '3':\n",
    "                    plt.bar(x=[1+width, 2+width, 3+width, 4+width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C1',\n",
    "                           label='Support')\n",
    "            if '冲刺' in list(dict_.keys())[i] and phase=='3':\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '1':\n",
    "                    plt.bar(x=[1-width, 2-width, 3-width, 4-width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C0',\n",
    "                           label='Swinging back')\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '2':\n",
    "                    plt.bar(x=[1, 2, 3, 4], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C2',\n",
    "                           label='Swinging forward')\n",
    "                if list(dict_.keys())[i].split('_')[-1] == '3':\n",
    "                    plt.bar(x=[1+width, 2+width, 3+width, 4+width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C1',\n",
    "                           label='Support')\n",
    "    plt.xticks([1,2,3,4],['In\\n-phase','Anti\\n-phase','A1','A2'],fontsize=16)\n",
    "    plt.yticks(fontsize=16)\n",
    "    plt.legend(fontsize=12,loc='upper right')\n",
    "    plt.ylabel('Number',fontsize=18)\n",
    "    if phase == '1': title+=' \\nin Midway'\n",
    "    if phase == '2': title+=' \\nin Boost'\n",
    "    if phase == '3': title+=' \\nin Sprint'\n",
    "    plt.title(title, fontsize=20)\n",
    "\n",
    "for i in range(1,4):\n",
    "    plot('The left hip with The left knee', '{}'.format(i))\n",
    "    plt.savefig('Figure/健将运动员对比（左髋关节&左膝关节）_{}_s.jpg'.format(i),dpi=300,bbox_inches = 'tight')\n",
    "    plt.show()\n",
    "    plot('The left knee with The left ankle', '{}'.format(i))\n",
    "    plt.savefig('Figure/健将运动员对比（左膝关节&左踝关节）_{}_s.jpg'.format(i),dpi=300,bbox_inches = 'tight')\n",
    "    plt.show()\n",
    "    plot('The right hip with The right knee', '{}'.format(i))\n",
    "    plt.savefig('Figure/健将运动员对比（右髋关节&右膝关节）_{}_s.jpg'.format(i),dpi=300,bbox_inches = 'tight')\n",
    "    plt.show()\n",
    "    plot('The right knee with The right ankle', '{}'.format(i))\n",
    "    plt.savefig('Figure/健将运动员对比（右膝关节&右踝关节）_{}_s.jpg'.format(i),dpi=300,bbox_inches = 'tight')\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 三个等级运动员的对比"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "from openpyxl import load_workbook\n",
    "import  pandas  as pd\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "def removeNan(data1):\n",
    "    try:\n",
    "        x = np.where(np.isnan(data1)==True)[0]\n",
    "        data1 = data1.tolist()\n",
    "        for i in range(len(x)-1,-1,-1):\n",
    "            data1.remove(data1[x[i]])\n",
    "    except:\n",
    "        data1 = data1.tolist()\n",
    "    return data1\n",
    "\n",
    "def getData(data, xindex=None, yindex=None):\n",
    "    # 获取数据\n",
    "    index1 = data[data.iloc[:,xindex]=='后摆阶段'].index.tolist()[0]\n",
    "    index2 = data[data.iloc[:,xindex]=='前摆阶段'].index.tolist()[0]\n",
    "    index3 = data[data.iloc[:,xindex]=='支撑阶段'].index.tolist()[0]\n",
    "    data1 = np.array(data.iloc[index1:index2, [yindex]]).T[0]\n",
    "    data1 = removeNan(data1)\n",
    "    data2 = np.array(data.iloc[index2:index3, [yindex]]).T[0]\n",
    "    data2 = removeNan(data2)\n",
    "    data3 = np.array(data.iloc[index3:, [yindex]]).T[0]\n",
    "    data3= removeNan(data3)\n",
    "    return lineInsert(data1), lineInsert(data2), lineInsert(data3)\n",
    "\n",
    "def getDataFull(data, xindex=None, yindex=None):\n",
    "    # 获取数据\n",
    "    index1 = data[data.iloc[:,xindex]=='后摆阶段'].index.tolist()[0]\n",
    "    index2 = data[data.iloc[:,xindex]=='前摆阶段'].index.tolist()[0]\n",
    "    index3 = data[data.iloc[:,xindex]=='支撑阶段'].index.tolist()[0]\n",
    "    data1 = np.array(data.iloc[index1:index2, [yindex]]).T[0]\n",
    "    data1 = removeNan(data1)\n",
    "    data2 = np.array(data.iloc[index2:index3, [yindex]]).T[0]\n",
    "    data2 = removeNan(data2)\n",
    "    data3 = np.array(data.iloc[index3:, [yindex]]).T[0]\n",
    "    data3= removeNan(data3)\n",
    "    data = data1+data2[1:]+data3[1:]\n",
    "    return lineInsert(data)\n",
    "\n",
    "def lineInsert(data1):\n",
    "    data1_ = np.zeros((101,1))\n",
    "    interval = int((data1_.shape[0]+(len(data1)-1)-2)/(len(data1)-1))\n",
    "    data1_[0:interval, 0] = np.linspace(data1[0], data1[1], interval)\n",
    "    for i in range(0, len(data1)-3):\n",
    "        data1_[interval+i*(interval-1):interval+i*(interval-1)+(interval-1), 0] = np.linspace(data1[i+1], data1[i+2], interval)[1: ]\n",
    "    surplus_number = data1_.shape[0]-interval-(interval - 1)*(len(data1)-3)\n",
    "    data1_[-surplus_number-1: , 0] = np.linspace(data1[-2], data1[-1], surplus_number+1)\n",
    "    return data1_\n",
    "\n",
    "dict_ = {}\n",
    "for k in ['途中','加速','冲刺']:\n",
    "    root = 'C:/code/北体数据处理/肢体角度数据/二级运动员数据/二级运动员{}段（后摆、前摆、支撑）.xlsx'.format(k)\n",
    "    wb = load_workbook(root)\n",
    "    sheets = wb.worksheets   # 获取当前所有的sheet\n",
    "    for ss in range(len(sheets)):\n",
    "        sheet1 = sheets[ss]\n",
    "        df=pd.read_excel(root,sheet_name=sheet1.title)\n",
    "        data=df.head(n=sheet1.max_row)\n",
    "        data1 = getDataFull(data, xindex=0, yindex=1)\n",
    "        data2 = getDataFull(data, xindex=0, yindex=2)\n",
    "        data3 = getDataFull(data, xindex=0, yindex=3)\n",
    "        data4 = getDataFull(data, xindex=5, yindex=6)\n",
    "        data5 = getDataFull(data, xindex=5, yindex=7)\n",
    "        data6 = getDataFull(data, xindex=5, yindex=8)\n",
    "        pair = [[1,2],[2,3],[4,5],[5,6]]\n",
    "        for i in pair:\n",
    "            str_ = ''\n",
    "            str_+= '二级_'\n",
    "            if i == [1,2]:str_+='The left hip with The left knee'\n",
    "            if i == [2,3]:str_+='The left knee with The left ankle'\n",
    "            if i == [4,5]:str_+='The right hip with The right knee'\n",
    "            if i == [5,6]:str_+='The right knee with The right ankle'\n",
    "            num_ = CA(eval('data{}'.format(i[0])), eval('data{}'.format(i[1])), 2)[:4,1]\n",
    "            if str_ not in dict_.keys():\n",
    "                dict_[str_] = []\n",
    "                dict_[str_].append(num_.tolist())\n",
    "            else:\n",
    "                dict_[str_].append(num_.tolist())  \n",
    "for k in ['途中','加速','冲刺']:\n",
    "    root = 'C:/code/北体数据处理/肢体角度数据/一级运动员数据/一级运动员{}跑数据.xlsx'.format(k)\n",
    "    wb = load_workbook(root)\n",
    "    sheets = wb.worksheets   # 获取当前所有的sheet\n",
    "    for ss in range(len(sheets)):\n",
    "        sheet1 = sheets[ss]\n",
    "        df=pd.read_excel(root,sheet_name=sheet1.title)\n",
    "        data=df.head(n=sheet1.max_row)\n",
    "        data1 = getDataFull(data, xindex=0, yindex=1)\n",
    "        data2 = getDataFull(data, xindex=0, yindex=2)\n",
    "        data3 = getDataFull(data, xindex=0, yindex=3)\n",
    "        data4 = getDataFull(data, xindex=5, yindex=6)\n",
    "        data5 = getDataFull(data, xindex=5, yindex=7)\n",
    "        data6 = getDataFull(data, xindex=5, yindex=8)\n",
    "        pair = [[1,2],[2,3],[4,5],[5,6]]\n",
    "        for i in pair:\n",
    "            str_ = ''\n",
    "            str_+='一级_'\n",
    "            if i == [1,2]:str_+='The left hip with The left knee'\n",
    "            if i == [2,3]:str_+='The left knee with The left ankle'\n",
    "            if i == [4,5]:str_+='The right hip with The right knee'\n",
    "            if i == [5,6]:str_+='The right knee with The right ankle'\n",
    "            num_ = CA(eval('data{}'.format(i[0])), eval('data{}'.format(i[1])), 2)[:4,1]\n",
    "            if str_ not in dict_.keys():\n",
    "                dict_[str_] = []\n",
    "                dict_[str_].append(num_.tolist())\n",
    "            else:\n",
    "                dict_[str_].append(num_.tolist())\n",
    "for k in ['途中','加速','冲刺']:\n",
    "    root = 'C:/code/北体数据处理/肢体角度数据/健将运动员数据/健将运动员{}阶段数据.xlsx'.format(k)\n",
    "    wb = load_workbook(root)\n",
    "    sheets = wb.worksheets   # 获取当前所有的sheet\n",
    "    for ss in range(len(sheets)):\n",
    "        sheet1 = sheets[ss]\n",
    "        df=pd.read_excel(root,sheet_name=sheet1.title)\n",
    "        data=df.head(n=sheet1.max_row)\n",
    "        data1 = getDataFull(data, xindex=0, yindex=1)\n",
    "        data2 = getDataFull(data, xindex=0, yindex=2)\n",
    "        data3 = getDataFull(data, xindex=0, yindex=3)\n",
    "        data4 = getDataFull(data, xindex=6, yindex=7)\n",
    "        data5 = getDataFull(data, xindex=6, yindex=8)\n",
    "        data6 = getDataFull(data, xindex=6, yindex=9)\n",
    "        pair = [[1,2],[2,3],[4,5],[5,6]]\n",
    "        for i in pair:\n",
    "            str_ = ''\n",
    "            str_ += '健将_'\n",
    "            if i == [1,2]:str_+='The left hip with The left knee'\n",
    "            if i == [2,3]:str_+='The left knee with The left ankle'\n",
    "            if i == [4,5]:str_+='The right hip with The right knee'\n",
    "            if i == [5,6]:str_+='The right knee with The right ankle'\n",
    "            num_ = CA(eval('data{}'.format(i[0])), eval('data{}'.format(i[1])), 2)[:4,1]\n",
    "            if str_ not in dict_.keys():\n",
    "                dict_[str_] = []\n",
    "                dict_[str_].append(num_.tolist())\n",
    "            else:\n",
    "                dict_[str_].append(num_.tolist())\n",
    "print(dict_.keys())\n",
    "\n",
    "def plot(title):\n",
    "    for i in range(len(list(dict_.keys()))):\n",
    "        value = dict_[list(dict_.keys())[i]]\n",
    "        dict_[list(dict_.keys())[i]] = np.array(value)\n",
    "        value = dict_[list(dict_.keys())[i]]\n",
    "        mean_ = value.mean(0) \n",
    "        std_ = value.std(0)\n",
    "        error_params=dict(elinewidth=1,ecolor='k',capsize=6)\n",
    "        width = 0.25\n",
    "        if title in list(dict_.keys())[i]: \n",
    "            if '二级' in list(dict_.keys())[i]:\n",
    "                plt.bar(x=[1-width, 2-width, 3-width, 4-width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C0',\n",
    "                       label='Second grade')\n",
    "            if '一级' in list(dict_.keys())[i]:\n",
    "                plt.bar(x=[1, 2, 3, 4], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C2',\n",
    "                       label='First grade')\n",
    "            if '健将' in list(dict_.keys())[i]:\n",
    "                plt.bar(x=[1+width, 2+width, 3+width, 4+width], height=mean_, width=width,yerr=std_, error_kw=error_params,color='C1',\n",
    "                       label='Master grade')\n",
    "    plt.xticks([1,2,3,4],['In\\n-phase','Anti\\n-phase','A1','A2'],fontsize=16)\n",
    "    plt.yticks(fontsize=16)\n",
    "    plt.legend(fontsize=12,loc='upper right')\n",
    "    plt.ylabel('Number',fontsize=18)\n",
    "    plt.title(title, fontsize=20)\n",
    "\n",
    "\n",
    "plot('The left hip with The left knee')\n",
    "plt.savefig('Figure/三等级运动员对比（左髋关节&左膝关节）.jpg',dpi=300,bbox_inches = 'tight')\n",
    "plt.show()\n",
    "plot('The left knee with The left ankle')\n",
    "plt.savefig('Figure/三等级运动员对比（左膝关节&左踝关节）.jpg',dpi=300,bbox_inches = 'tight')\n",
    "plt.show()\n",
    "plot('The right hip with The right knee')\n",
    "plt.savefig('Figure/三等级运动员对比（右髋关节&右膝关节）.jpg',dpi=300,bbox_inches = 'tight')\n",
    "plt.show()\n",
    "plot('The right knee with The right ankle')\n",
    "plt.savefig('Figure/三等级运动员对比（右膝关节&右踝关节）.jpg',dpi=300,bbox_inches = 'tight')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 插值数据保存"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "from openpyxl import load_workbook\n",
    "from openpyxl import Workbook\n",
    "import  pandas  as pd\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "def removeNan(data1):\n",
    "    try:\n",
    "        x = np.where(np.isnan(data1)==True)[0]\n",
    "        data1 = data1.tolist()\n",
    "        for i in range(len(x)-1,-1,-1):\n",
    "            data1.remove(data1[x[i]])\n",
    "    except:\n",
    "        data1 = data1.tolist()\n",
    "    return data1\n",
    "\n",
    "def getData(data, xindex=None, yindex=None):\n",
    "    # 获取数据\n",
    "    index1 = data[data.iloc[:,xindex]=='后摆阶段'].index.tolist()[0]\n",
    "    index2 = data[data.iloc[:,xindex]=='前摆阶段'].index.tolist()[0]\n",
    "    index3 = data[data.iloc[:,xindex]=='支撑阶段'].index.tolist()[0]\n",
    "    data1 = np.array(data.iloc[index1:index2, [yindex]]).T[0]\n",
    "    data1 = removeNan(data1)\n",
    "    data2 = np.array(data.iloc[index2:index3, [yindex]]).T[0]\n",
    "    data2 = removeNan(data2)\n",
    "    data3 = np.array(data.iloc[index3:, [yindex]]).T[0]\n",
    "    data3= removeNan(data3)\n",
    "    return lineInsert(data1), lineInsert(data2), lineInsert(data3)\n",
    "\n",
    "def lineInsert(data1):\n",
    "    data1_ = np.zeros((101,1))\n",
    "    interval = int((data1_.shape[0]+(len(data1)-1)-2)/(len(data1)-1))\n",
    "    data1_[0:interval, 0] = np.linspace(data1[0], data1[1], interval)\n",
    "    for i in range(0, len(data1)-3):\n",
    "        data1_[interval+i*(interval-1):interval+i*(interval-1)+(interval-1), 0] = np.linspace(data1[i+1], data1[i+2], interval)[1: ]\n",
    "    surplus_number = data1_.shape[0]-interval-(interval - 1)*(len(data1)-3)\n",
    "    data1_[-surplus_number-1: , 0] = np.linspace(data1[-2], data1[-1], surplus_number+1)\n",
    "    return data1_\n",
    "\n",
    "#生成一个 Workbook 的实例化对象，wb即代表一个工作簿（一个 Excel 文件）\n",
    "for k in ['途中','加速','冲刺']:\n",
    "    root = 'C:/code/北体数据处理/肢体角度数据/一级运动员数据/一级运动员{}跑数据.xlsx'.format(k)\n",
    "    wb = load_workbook(root)\n",
    "    sheets = wb.worksheets   # 获取当前所有的sheet\n",
    "    \n",
    "    rb = openpyxl.Workbook()\n",
    "    for ss in range(len(sheets)):\n",
    "        sheet1 = sheets[ss]\n",
    "        rb.create_sheet(index=ss,title=sheet1.title)\n",
    "    rb.save('插值后_一级运动员{}跑数据.xlsx'.format(k))\n",
    "    rb = load_workbook('插值后_一级运动员{}跑数据.xlsx'.format(k))\n",
    "    \n",
    "    for ss in range(len(sheets)):\n",
    "        sheet1 = sheets[ss]\n",
    "        df=pd.read_excel(root,sheet_name=sheet1.title)\n",
    "        data=df.head(n=sheet1.max_row)\n",
    "        data1_1, data1_2, data1_3 = getData(data, xindex=0, yindex=1) # 读取所有数据\n",
    "        data2_1, data2_2, data2_3 = getData(data, xindex=0, yindex=2)\n",
    "        data3_1, data3_2, data3_3 = getData(data, xindex=0, yindex=3)\n",
    "        data4_1, data4_2, data4_3 = getData(data, xindex=5, yindex=6)\n",
    "        data5_1, data5_2, data5_3 = getData(data, xindex=5, yindex=7)\n",
    "        data6_1, data6_2, data6_3 = getData(data, xindex=5, yindex=8)\n",
    "        \n",
    "        datax = []\n",
    "        work_sheet = rb[sheet1.title]\n",
    "        for i in range(1, 7):\n",
    "            datax.append(np.concatenate((eval('data{}_1'.format(i)), eval('data{}_2'.format(i)), eval('data{}_3'.format(i)))))\n",
    "        print(np.array(datax[0]).shape)\n",
    "        work_sheet['A1'],work_sheet['B1'],work_sheet['C1'],work_sheet['D1'],work_sheet['E1'],work_sheet['F1']=['左髋关节','左膝关节','左踝关节','右髋关节','右膝关节','右踝关节']\n",
    "        data_excel = []\n",
    "        for i in range(303):\n",
    "            data_excel.append([datax[0][i,0], datax[1][i,0], datax[2][i,0], datax[3][i,0], datax[4][i,0], datax[5][i,0]])\n",
    "        for each in data_excel:\n",
    "            work_sheet.append(each)\n",
    "            \n",
    "    rb.save('插值后_一级运动员{}跑数据.xlsx'.format(k))\n",
    "        \n",
    "#         for i in range(1,6):\n",
    "#             eval('data{}'.format(i))=np.concatenate((eval('data{}_1'.format(i)), eval('data{}_2'.format(i)), eval('data{}_3'.format(i))), axis=0)\n",
    "        \n",
    "#         # 获取活跃的工作表，ws代表wb(工作簿)的一个工作表\n",
    "#         ws = rb.active\n",
    "#         #更改工作表ws的title\n",
    "#         data_excel = []\n",
    "#         #将字典中的每对数据（键，值）以列表形式传入data_excel列表\n",
    "#         for each in data:\n",
    "#             data_excel.append([each, data[each]])\n",
    "#         #将data_excel列表内的内容存入工作表\n",
    "#         for each in data_excel:\n",
    "#             ws.append(each)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "from openpyxl import load_workbook\n",
    "from openpyxl import Workbook\n",
    "import  pandas  as pd\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "def removeNan(data1):\n",
    "    try:\n",
    "        x = np.where(np.isnan(data1)==True)[0]\n",
    "        data1 = data1.tolist()\n",
    "        for i in range(len(x)-1,-1,-1):\n",
    "            data1.remove(data1[x[i]])\n",
    "    except:\n",
    "        data1 = data1.tolist()\n",
    "    return data1\n",
    "\n",
    "def getData(data, xindex=None, yindex=None):\n",
    "    # 获取数据\n",
    "    index1 = data[data.iloc[:,xindex]=='后摆阶段'].index.tolist()[0]\n",
    "    index2 = data[data.iloc[:,xindex]=='前摆阶段'].index.tolist()[0]\n",
    "    index3 = data[data.iloc[:,xindex]=='支撑阶段'].index.tolist()[0]\n",
    "    data1 = np.array(data.iloc[index1:index2, [yindex]]).T[0]\n",
    "    data1 = removeNan(data1)\n",
    "    data2 = np.array(data.iloc[index2:index3, [yindex]]).T[0]\n",
    "    data2 = removeNan(data2)\n",
    "    data3 = np.array(data.iloc[index3:, [yindex]]).T[0]\n",
    "    data3= removeNan(data3)\n",
    "    return lineInsert(data1), lineInsert(data2), lineInsert(data3)\n",
    "\n",
    "def lineInsert(data1):\n",
    "    data1_ = np.zeros((101,1))\n",
    "    interval = int((data1_.shape[0]+(len(data1)-1)-2)/(len(data1)-1))\n",
    "    data1_[0:interval, 0] = np.linspace(data1[0], data1[1], interval)\n",
    "    for i in range(0, len(data1)-3):\n",
    "        data1_[interval+i*(interval-1):interval+i*(interval-1)+(interval-1), 0] = np.linspace(data1[i+1], data1[i+2], interval)[1: ]\n",
    "    surplus_number = data1_.shape[0]-interval-(interval - 1)*(len(data1)-3)\n",
    "    data1_[-surplus_number-1: , 0] = np.linspace(data1[-2], data1[-1], surplus_number+1)\n",
    "    return data1_\n",
    "\n",
    "#生成一个 Workbook 的实例化对象，wb即代表一个工作簿（一个 Excel 文件）\n",
    "for k in ['途中','加速','冲刺']:\n",
    "    root = 'C:/code/北体数据处理/肢体角度数据/二级运动员数据/二级运动员{}段（后摆、前摆、支撑）.xlsx'.format(k)\n",
    "    wb = load_workbook(root)\n",
    "    sheets = wb.worksheets   # 获取当前所有的sheet\n",
    "    \n",
    "    rb = openpyxl.Workbook()\n",
    "    for ss in range(len(sheets)):\n",
    "        sheet1 = sheets[ss]\n",
    "        rb.create_sheet(index=ss,title=sheet1.title)\n",
    "    rb.save('插值后_二级运动员{}段（后摆、前摆、支撑）.xlsx'.format(k))\n",
    "    rb = load_workbook('插值后_二级运动员{}段（后摆、前摆、支撑）.xlsx'.format(k))\n",
    "    \n",
    "    for ss in range(len(sheets)):\n",
    "        sheet1 = sheets[ss]\n",
    "        df=pd.read_excel(root,sheet_name=sheet1.title)\n",
    "        data=df.head(n=sheet1.max_row)\n",
    "        data1_1, data1_2, data1_3 = getData(data, xindex=0, yindex=1) # 读取所有数据\n",
    "        data2_1, data2_2, data2_3 = getData(data, xindex=0, yindex=2)\n",
    "        data3_1, data3_2, data3_3 = getData(data, xindex=0, yindex=3)\n",
    "        data4_1, data4_2, data4_3 = getData(data, xindex=5, yindex=6)\n",
    "        data5_1, data5_2, data5_3 = getData(data, xindex=5, yindex=7)\n",
    "        data6_1, data6_2, data6_3 = getData(data, xindex=5, yindex=8)\n",
    "        \n",
    "        datax = []\n",
    "        work_sheet = rb[sheet1.title]\n",
    "        for i in range(1, 7):\n",
    "            datax.append(np.concatenate((eval('data{}_1'.format(i)), eval('data{}_2'.format(i)), eval('data{}_3'.format(i)))))\n",
    "        print(np.array(datax[0]).shape)\n",
    "        work_sheet['A1'],work_sheet['B1'],work_sheet['C1'],work_sheet['D1'],work_sheet['E1'],work_sheet['F1']=['左髋关节','左膝关节','左踝关节','右髋关节','右膝关节','右踝关节']\n",
    "        data_excel = []\n",
    "        for i in range(303):\n",
    "            data_excel.append([datax[0][i,0], datax[1][i,0], datax[2][i,0], datax[3][i,0], datax[4][i,0], datax[5][i,0]])\n",
    "        for each in data_excel:\n",
    "            work_sheet.append(each)\n",
    "            \n",
    "    rb.save('插值后_二级运动员{}段（后摆、前摆、支撑）.xlsx'.format(k))\n",
    "        \n",
    "#         for i in range(1,6):\n",
    "#             eval('data{}'.format(i))=np.concatenate((eval('data{}_1'.format(i)), eval('data{}_2'.format(i)), eval('data{}_3'.format(i))), axis=0)\n",
    "        \n",
    "#         # 获取活跃的工作表，ws代表wb(工作簿)的一个工作表\n",
    "#         ws = rb.active\n",
    "#         #更改工作表ws的title\n",
    "#         data_excel = []\n",
    "#         #将字典中的每对数据（键，值）以列表形式传入data_excel列表\n",
    "#         for each in data:\n",
    "#             data_excel.append([each, data[each]])\n",
    "#         #将data_excel列表内的内容存入工作表\n",
    "#         for each in data_excel:\n",
    "#             ws.append(each)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from openpyxl import load_workbook\n",
    "from openpyxl import Workbook\n",
    "import  pandas  as pd\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "def removeNan(data1):\n",
    "    try:\n",
    "        x = np.where(np.isnan(data1)==True)[0]\n",
    "        data1 = data1.tolist()\n",
    "        for i in range(len(x)-1,-1,-1):\n",
    "            data1.remove(data1[x[i]])\n",
    "    except:\n",
    "        data1 = data1.tolist()\n",
    "    return data1\n",
    "\n",
    "def getData(data, xindex=None, yindex=None):\n",
    "    # 获取数据\n",
    "    index1 = data[data.iloc[:,xindex]=='后摆阶段'].index.tolist()[0]\n",
    "    index2 = data[data.iloc[:,xindex]=='前摆阶段'].index.tolist()[0]\n",
    "    index3 = data[data.iloc[:,xindex]=='支撑阶段'].index.tolist()[0]\n",
    "    data1 = np.array(data.iloc[index1:index2, [yindex]]).T[0]\n",
    "    data1 = removeNan(data1)\n",
    "    data2 = np.array(data.iloc[index2:index3, [yindex]]).T[0]\n",
    "    data2 = removeNan(data2)\n",
    "    data3 = np.array(data.iloc[index3:, [yindex]]).T[0]\n",
    "    data3= removeNan(data3)\n",
    "    return lineInsert(data1), lineInsert(data2), lineInsert(data3)\n",
    "\n",
    "def lineInsert(data1):\n",
    "    data1_ = np.zeros((101,1))\n",
    "    interval = int((data1_.shape[0]+(len(data1)-1)-2)/(len(data1)-1))\n",
    "    data1_[0:interval, 0] = np.linspace(data1[0], data1[1], interval)\n",
    "    for i in range(0, len(data1)-3):\n",
    "        data1_[interval+i*(interval-1):interval+i*(interval-1)+(interval-1), 0] = np.linspace(data1[i+1], data1[i+2], interval)[1: ]\n",
    "    surplus_number = data1_.shape[0]-interval-(interval - 1)*(len(data1)-3)\n",
    "    data1_[-surplus_number-1: , 0] = np.linspace(data1[-2], data1[-1], surplus_number+1)\n",
    "    return data1_\n",
    "\n",
    "#生成一个 Workbook 的实例化对象，wb即代表一个工作簿（一个 Excel 文件）\n",
    "for k in ['途中','加速','冲刺']:\n",
    "    root = 'C:/code/北体数据处理/肢体角度数据/健将运动员数据/健将运动员{}阶段数据.xlsx'.format(k)\n",
    "    wb = load_workbook(root)\n",
    "    sheets = wb.worksheets   # 获取当前所有的sheet\n",
    "    \n",
    "    rb = openpyxl.Workbook()\n",
    "    for ss in range(len(sheets)):\n",
    "        sheet1 = sheets[ss]\n",
    "        rb.create_sheet(index=ss,title=sheet1.title)\n",
    "    rb.save('插值后_健将运动员{}阶段数据.xlsx'.format(k))\n",
    "    rb = load_workbook('插值后_健将运动员{}阶段数据.xlsx'.format(k))\n",
    "    \n",
    "    for ss in range(len(sheets)):\n",
    "        sheet1 = sheets[ss]\n",
    "        df=pd.read_excel(root,sheet_name=sheet1.title)\n",
    "        data=df.head(n=sheet1.max_row)\n",
    "        data1_1, data1_2, data1_3 = getData(data, xindex=0, yindex=1) # 读取所有数据\n",
    "        data2_1, data2_2, data2_3 = getData(data, xindex=0, yindex=2)\n",
    "        data3_1, data3_2, data3_3 = getData(data, xindex=0, yindex=3)\n",
    "        data4_1, data4_2, data4_3 = getData(data, xindex=6, yindex=7)\n",
    "        data5_1, data5_2, data5_3 = getData(data, xindex=6, yindex=8)\n",
    "        data6_1, data6_2, data6_3 = getData(data, xindex=6, yindex=9)\n",
    "        \n",
    "        datax = []\n",
    "        work_sheet = rb[sheet1.title]\n",
    "        for i in range(1, 7):\n",
    "            datax.append(np.concatenate((eval('data{}_1'.format(i)), eval('data{}_2'.format(i)), eval('data{}_3'.format(i)))))\n",
    "        print(np.array(datax[0]).shape)\n",
    "        work_sheet['A1'],work_sheet['B1'],work_sheet['C1'],work_sheet['D1'],work_sheet['E1'],work_sheet['F1']=['左髋关节','左膝关节','左踝关节','右髋关节','右膝关节','右踝关节']\n",
    "        data_excel = []\n",
    "        for i in range(303):\n",
    "            data_excel.append([datax[0][i,0], datax[1][i,0], datax[2][i,0], datax[3][i,0], datax[4][i,0], datax[5][i,0]])\n",
    "        for each in data_excel:\n",
    "            work_sheet.append(each)\n",
    "            \n",
    "    rb.save('插值后_健将运动员{}阶段数据.xlsx'.format(k))\n",
    "        \n",
    "#         for i in range(1,6):\n",
    "#             eval('data{}'.format(i))=np.concatenate((eval('data{}_1'.format(i)), eval('data{}_2'.format(i)), eval('data{}_3'.format(i))), axis=0)\n",
    "        \n",
    "#         # 获取活跃的工作表，ws代表wb(工作簿)的一个工作表\n",
    "#         ws = rb.active\n",
    "#         #更改工作表ws的title\n",
    "#         data_excel = []\n",
    "#         #将字典中的每对数据（键，值）以列表形式传入data_excel列表\n",
    "#         for each in data:\n",
    "#             data_excel.append([each, data[each]])\n",
    "#         #将data_excel列表内的内容存入工作表\n",
    "#         for each in data_excel:\n",
    "#             ws.append(each)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import openpyxl\n",
    "#生成一个 Workbook 的实例化对象，wb即代表一个工作簿（一个 Excel 文件）\n",
    "wb = openpyxl.Workbook()\n",
    "# 获取活跃的工作表，ws代表wb(工作簿)的一个工作表\n",
    "ws = wb.active\n",
    "#更改工作表ws的title\n",
    "ws.title = 'test_sheet1'\n",
    "#对ws的单个单元格传入数据\n",
    "ws['A1'] = '国家'\n",
    "ws['B1'] = '首都'\n",
    "data = {\n",
    "    '中国':'北京',\n",
    "    '韩国':'首尔',\n",
    "    '日本':'东京',\n",
    "    '泰国':'曼谷',\n",
    "    '马来西亚':'吉隆坡',\n",
    "    '越南':'河内',\n",
    "    '朝鲜':'平壤',\n",
    "    '印度':'新德里'\n",
    "    }\n",
    "data_excel = []\n",
    "#将字典中的每对数据（键，值）以列表形式传入data_excel列表\n",
    "for each in data:\n",
    "    data_excel.append([each, data[each]])\n",
    "#将data_excel列表内的内容存入工作表\n",
    "for each in data_excel:\n",
    "    ws.append(each)\n",
    "#注意：上述两个append方法是意义完全不同的两个方法\n",
    "wb.save('test.xlsx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "a=[1,2,3]\n",
    "b=[4,5,6]\n",
    "np.concatenate((a,b),axis=0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Old Code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from openpyxl import load_workbook\n",
    "import  pandas  as pd\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "# {'左髋关节':1, '左膝关节':2, '左踝关节':3, '右髋关节':7, '右膝关节':8, '右踝关节':9}\n",
    "def getData(data, xindex=None, yindex=None):\n",
    "    # 获取数据函数\n",
    "    index1 = data[data.iloc[:,xindex]=='后摆阶段'].index.tolist()[0]\n",
    "    index2 = data[data.iloc[:,xindex]=='前摆阶段'].index.tolist()[0]\n",
    "    index3 = data[data.iloc[:,xindex]=='支撑阶段'].index.tolist()[0]\n",
    "    data1 = np.array(data.iloc[index1:index2, [yindex]]).T[0]\n",
    "    data2 = np.array(data.iloc[index2:index3, [yindex]]).T[0]\n",
    "    data3 = np.array(data.iloc[index3:, [yindex]])\n",
    "    try:\n",
    "        x = np.where(np.isnan(data3)==True)[0][0]\n",
    "        data3 = np.array(data3.tolist()[:x]).T[0]\n",
    "    except:\n",
    "        data3 = np.array(data.iloc[index3:, [yindex]]).T[0]\n",
    "    return lineInsert(data1), lineInsert(data2), lineInsert(data3)\n",
    "\n",
    "def lineInsert(data1):\n",
    "    # 插值函数\n",
    "    data1_ = np.zeros((101,1))\n",
    "    interval = int((data1_.shape[0]+(len(data1)-1)-2)/(len(data1)-1))\n",
    "    data1_[0:interval, 0] = np.linspace(data1[0], data1[1], interval)\n",
    "    for i in range(0, len(data1)-3):\n",
    "        data1_[interval+i*(interval-1):interval+i*(interval-1)+(interval-1), 0] = np.linspace(data1[i+1], data1[i+2], interval)[1: ]\n",
    "    surplus_number = data1_.shape[0]-interval-(interval - 1)*(len(data1)-3)\n",
    "    data1_[-surplus_number-1: , 0] = np.linspace(data1[-2], data1[-1], surplus_number+1)\n",
    "    return data1_\n",
    "\n",
    "root = 'C:/code/北体数据处理/肢体角度数据/一级运动员数据/一级运动员冲刺跑数据.xlsx'\n",
    "wb = load_workbook(root)\n",
    "sheets = wb.worksheets   # 获取当前文件所有的sheet\n",
    "\n",
    "dict_ = {}\n",
    "for ss in range(len(sheets)):\n",
    "    sheet1 = sheets[ss]\n",
    "    df=pd.read_excel(root,sheet_name=sheet1.title)\n",
    "    data=df.head(n=sheet1.max_row)\n",
    "    data1_1, data1_2, data1_3 = getData(data, xindex=0, yindex=1) # 读取所有数据\n",
    "    data2_1, data2_2, data2_3 = getData(data, xindex=0, yindex=2)\n",
    "    data3_1, data3_2, data3_3 = getData(data, xindex=0, yindex=3)\n",
    "    data4_1, data4_2, data4_3 = getData(data, xindex=5, yindex=6)\n",
    "    data5_1, data5_2, data5_3 = getData(data, xindex=5, yindex=7)\n",
    "    data6_1, data6_2, data6_3 = getData(data, xindex=5, yindex=8)\n",
    "    pair = [[1,2],[2,3],[4,5],[5,6]]\n",
    "    for i in pair:\n",
    "        for j in range(1,4):\n",
    "            str_ = ''\n",
    "            if i == [1,2]:str_+='The left hip with The left knee'\n",
    "            if i == [2,3]:str_+='The left knee with The left ankle'\n",
    "            if i == [4,5]:str_+='The right hip with The left knee'\n",
    "            if i == [5,6]:str_+='The right knee with The left ankle'\n",
    "            if j == 1: str_+=' in\\n The phase of swinging back'\n",
    "            if j == 2: str_+=' in\\n The phase of swinging forward'\n",
    "            if j == 3: str_+=' in\\n The phase of support'\n",
    "            num_ = CA(eval('data{}_{}'.format(i[0], j)), eval('data{}_{}'.format(i[1], j)), 2)[:4,1]\n",
    "            if str_ not in dict_.keys():\n",
    "                dict_[str_] = []\n",
    "                dict_[str_].append(num_.tolist())\n",
    "            else:\n",
    "                dict_[str_].append(num_.tolist())\n",
    "#             if str(i)+str(j) not in dict_.keys():\n",
    "#                 dict_[str(i)+str(j)] = []\n",
    "#                 dict_[str(i)+str(j)].append(num_.tolist())\n",
    "#             else:\n",
    "#                 dict_[str(i)+str(j)].append(num_.tolist())\n",
    "# print(list(dict_.keys()))\n",
    "\n",
    "# for i in range(len(list(dict_.keys()))):\n",
    "#     value = dict_[list(dict_.keys())[i]]\n",
    "#     dict_[list(dict_.keys())[i]] = np.array(value)\n",
    "#     value = dict_[list(dict_.keys())[i]]\n",
    "#     mean_ = value.mean(0) \n",
    "#     std_ = value.std(0)\n",
    "#     error_params=dict(elinewidth=2,ecolor='k',capsize=10)\n",
    "#     plt.bar(x=[1, 2, 3, 4], height=mean_, width=0.5,yerr=std_, error_kw=error_params)\n",
    "#     plt.xticks([1,2,3,4],['In\\n-phase','Anti\\n-phase','A1','A2'],fontsize=16)\n",
    "#     plt.yticks(fontsize=16)\n",
    "#     plt.ylabel('Number',fontsize=18)\n",
    "#     plt.title(list(dict_.keys())[i], fontsize=20)\n",
    "#     plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "try:    \n",
    "    !jupyter nbconvert --to python file_name.ipynb\n",
    "    # python即转化为.py，script即转化为.html\n",
    "    # file_name.ipynb即当前module的文件名\n",
    "except:\n",
    "    pass"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "py374",
   "language": "python",
   "name": "py374"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "227.027px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
